Closed jelle-blaauw closed 1 year ago
I was actually able to come up with this:
class FilterQuery : ESQuery(name = "filter")
class FilterAgg(
block: (FilterQuery.() -> ESQuery)
) : AggQuery("filter") {
init {
val config = FilterQuery()
val query = block.invoke(config)
config[query.name] = query
put(name, config)
}
}
which can be used as follows:
agg("my-agg-name", FilterAgg {
bool {
must(
nested {
path = "someField"
query = bool {
must(
exists("someField"),
terms("someField.somePath", "someValue"),
)
}
}
)
}
})
It can probably improved, and there still needs to be a clean way to retrieve the results, but at least it works.
Cool thanks! That looks like it should work. When I find some time, I'll squeeze in a pull request. Might be a while because I'm super busy right now.
Describe the enhancement
I'd like to be able to do filter aggregations, like so:
Why is this needed?
It's an ElasticSearch feature, so it should be in this lib as well.
How do you think it should be done?
I think an extension to
AggQuery
can be made which uses aBoolQuery
as the "body".Will you be able to help with a pull request?
Maybe.