Welcome to Elasticmagic¶
Elasticmagic implements advanced type awareness DSL for Kotlin to construct Elasticsearch queries.
Warning
The library is in very alpha status. API may change significantly at any time. Use it on your own risk
Getting started¶
Setup¶
Add following dependencies in your build.gradle.kts
script:
repositories {
mavenCentral()
}
val elasticmagicVersion = "0.0.30"
val ktorVersion = "2.2.2"
dependencies {
// Elasticmagic core api
implementation("dev.evo.elasticmagic:elasticmagic:$elasticmagicVersion")
// Json serialization using kotlinx.serialization
implementation("dev.evo.elasticmagic:elasticmagic-serde-kotlinx-json:$elasticmagicVersion")
// Transport that uses ktor http client
implementation("dev.evo.elasticmagic:elasticmagic-transport-ktor:$elasticmagicVersion")
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
Usage¶
First you need to describe a document (represents a mapping in terms of Elasticsearch):
Now create ElasticsearchCluster
object. It is an entry point for executing search queries:
Any ElasticsearchCluster
needs an ElasticsearchTransport
. We will use
the ElasticsearchKtorTransport
that utilises Ktor
http client.
Here are examples of creating transports for the cluster.
JVM:
Native:
Create our index if it does not exist or update the mapping otherwise:
Describe document sources and index them:
And finally we can search our data:
Run the sample¶
You can find fully working example inside samples
And run it with as JVM application (of cause you need Elasticsearch available at localhost:9200
):
./gradlew :samples:run
or native:
./gradlew :samples:runDebugExecutableNative