mbuhot / eskotlin

Elasticsearch Query DSL for Kotlin
MIT License
136 stars 28 forks source link

Basic dynamic queries #4

Closed puug closed 7 years ago

puug commented 7 years ago

Been playing with a simple idea to introduce basic dynamic queries by making them conditional. ie

val query = bool {
    must {
        term { "user" to "kimchy" }
    }
    filter(isTech()) {
        term { "tag" to "tech" }
    }
    filter(!isTech()) {
        match_all { }
    }
    must_not {
        range {
            "age" to {
                from = 10
                to = 20
            }
        }
    }
    should = listOf(
        term(isAmazing()) { "tag" to "wow" },
        term { "tag" to "elasticsearch" })
    minimum_should_match = 1
    boost = 1.0f
}

I'm not overly happy with the implementation, so interested if you have any other ideas - I haven't let it stew in my head for long so it's a little raw, and I haven't used it in anger to see how much it pollutes the DSL in a real world scenario.

mbuhot commented 7 years ago

Closing after fleshing out some alternatives in #5