Hello,
I am developing a web application to visualize data in an elastic and I am inspired by the queries made by Kibana in the Discover application by going to inspect the query object created in the Inspect tab of Discover.
I get the impression that apart from the negative terms that use "bool":{"must_not":[]}
to create the query, the must[]
query (which is not the same thing as must_not[]
anyway) is never used and instead Kibana uses a nesting of filter[]
query and should[]
query.
Is there any particular reason not to use the must[]
query, especially if the query contains only "AND " operators?
Moreover, queries containing only "AND " operators have exactly the same nesting structure of should[]
as queries containing only "OR " operators. So how does Kibana separate "I want this and this and this " from "I want this or this or this ".
In my previous query interpreter I had a should[]
object that contained several must[]
objects. Each must[]
object stored the "AND " operators side by side, so each time there was an "OR " operator I created a new must[]
object in the main should[]
object.
Now that I want to use the same structure as the queries made by Kibana's Discover application, I see that the parent object is a filter[]
followed by a nesting of should[]
, so how can I separate an "AND " from an "OR "?
Example of a query created by Kibana retrieved from the Inspect tab of the Discover application for the following query:
field1:"match_field1" AND field2:"match_field2" AND field3:"match_field3" AND field4:"match_field4" AND field5:"match_field5"
This gives the query:
"query": {
"bool": {
"must": [],
"filter": [
{
"bool": {
"filter": [
{
"bool": {
"should": [
{
"match_phrase": {
"field1": "match_field1"
}
}
],
"minimum_should_match": 1
}
},
{
"bool": {
"filter": [
{
"bool": {
"should": [
{
"match_phrase": {
"field2": "match_field2"
}
}
],
"minimum_should_match": 1
}
},
{
"bool": {
"filter": [
{
"bool": {
"should": [
{
"match_phrase": {
"field3": "match_field3"
}
}
],
"minimum_should_match": 1
}
},
{
"bool": {
"filter": [
{
"bool": {
"should": [
{
"match_phrase": {
"field4": "match_field4"
}
}
],
"minimum_should_match": 1
}
},
{
"bool": {
"should": [
{
"match_phrase": {
"field5": "match_field5"
}
}
],
"minimum_should_match": 1
}
}
]
}
}
]
}
}
]
}
}
]
}
},
{
"range": {
"@timestamp": {
"gte": "2021-05-04T15:14:08.772Z",
"lte": "2022-08-04T15:14:08.772Z",
"format": "strict_date_optional_time"
}
}
}
],
"should": [],
"must_not": []
}
},
Thank you in advance if you take the time to help me.