Is there a way to include KQL (nearly the syntax) into a DSL bool query for example. I have an aggregation whose buckets make up a dataset, which is "flattened" into a table view. Within the UI we allow KQL filtering, but upon a given action I get the set of data included in a row, to use as boolean query WHERE clause like values for getting the document instances that we included in that set.
So I construct a bool query which is great and works fine from those properties:
{
"query": {
"bool": {
"must": [{
"match": {
"color": "red"
},{
"shape": "circle"
}
}]
}
}
}
but I also get the KQL string the user used to filter on the dataset within the UI item.available: true
Is there a way to include this within the boolean query I have already constructed through the java high level rest client / or just generic dsl for that matter?
I have tried query-string as it seems to be the closest in the documentation that I can find
{
"query": {
"bool": {
"must": [{
"match": {
"color": "red"
},{
"shape": "circle"
}
}]
},
"query_string" : {
"query" : "item.available: true"
}
}
}
but this doesn't seem to work in parallel with the bool query? any ideas? thanks as always
KQL is only available/exposed in the Kibana UI. Whenever Kibana communicates with Elasticsearch it is using Elasticsearch's query DSL. One notable exception is Lucene expressions (or KQL expressions translated into Lucene syntax) which will end up as search-strings in Elasticsearch query-string
-query, as you observed.
The query-string
-query is a "standard" Elasticsearch-query and can be used wherever any other query (e.g. match
-query) can be used. So yes, it should be possible to use a query-string
-query within a bool
-query, also when using language clients.