Hello,
I am doing a search on an index with a filter on a field which is a text with a field analyzer. In my query I want to have all the records which contains exactly both of the fields I have specified in my query, or none of those two parameters (based of some inputs of the user).
I have found two ways of doing the first query :
- With two terms query in the must query
{
"size": 0,
"query": {
"bool": {
"must": [
{ "terms":
{
"features": ["feature1"],
"boost": 1.0
}
},
{ "terms":
{
"features": ["feature2"],
"boost": 1.0
}
}
]
}
}
}
- With two terms query encapsulated in another bool query, so two encapsulated bool queries :
{
"size": 0,
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{ "terms":
{
"features": ["feature1"],
"boost": 1.0
}
},
{ "terms":
{
"features": ["feature2"],
"boost": 1.0
}
}
]
}
}
]
}
}
}
The second bool query is redundant in that case, but it actually helps me in my code when getting all the records that does not contain both those input parameters. I found out that without the bool encapsulator, the must_not query on its own behaves as an OR operator in SQL, but encapsulating with a bool query with a must, makes it behaving as an AND operator (which is what I need).
Regardless of that, I would like to know if encapsulating two bool queries this way has an impact in terms of performance for the query. In all the tests I have done, the second query run is always faster (whether it contained the encapsulated bool query or not), but I could not find out if one of them was actually faster than the other one.
Thanks in advance!