Elasticsearch Query DSL for Kotlin.
This library aims to minimize the gap between the Elasticsearch JSON query DSL, and the API used when writing kotlin applications. This integrates with the existing java API, only providing a nicer syntax to build the queries.
repositories {
mavenCentral()
...
maven {
url "http://dl.bintray.com/mbuhot/maven"
}
}
dependencies {
compile 'mbuhot:eskotlin:0.7.0'
...
}
See CHANGELOG for older versions supporting previous elasticsearch client versions.
Full details on bintray
<dependency>
<groupId>mbuhot</groupId>
<artifactId>eskotlin</artifactId>
<version>0.7.0</version>
<type>pom</type>
</dependency>
JSON:
{
"term" : { "user" : "Kimchy" }
}
Kotlin:
val query = term {
"user" to "Kimchy"
}
JSON:
{
"bool" : {
"must" : {
"term" : { "user" : "kimchy" }
},
"filter": {
"term" : { "tag" : "tech" }
},
"must_not" : {
"range" : {
"age" : { "from" : 10, "to" : 20 }
}
},
"should" : [
{
"term" : { "tag" : "wow" }
},
{
"term" : { "tag" : "elasticsearch" }
}
],
"minimum_should_match" : 1,
"boost" : 1.0
}
}
Kotlin:
val query = bool {
must {
term { "user" to "kimchy" }
}
filter {
term { "tag" to "tech" }
}
must_not {
range {
"age" {
from = 10
to = 20
}
}
}
should = listOf(
term { "tag" to "wow" },
term { "tag" to "elasticsearch" })
minimum_should_match = 1
boost = 1.0f
}
JSON:
{
"function_score": {
"query": {
"match_all": {}
},
"functions": [
{
"filter": {
"term": {
"foo": "bar"
}
},
"gauss": {
"baz": {
"scale": 1.0
}
}
},
{
"filter": {
"match_all": {}
},
"random_score": {
"seed": 234
}
},
{
"exp": {
"qux": {
"scale": 2.3
}
}
}
],
"score_mode": "max",
"boost_mode": "multiply",
"max_boost": 5.0,
"boost": 1.2,
"min_score": 0.001
}
}
Kotlin:
val query = function_score {
query = match_all { }
functions = listOf(
term { "foo" to "bar" } to gaussDecayFunction("baz", 1.0),
match_all { } to randomFunction(234L),
null to exponentialDecayFunction("qux", 2.3))
boost = 1.2f
boost_mode = "multiply"
score_mode = "max"
max_boost = 5.0f
min_score = 0.001f
}
See the src/test directory for more examples.
MIT - See LICENSE file for full text.