I have an index upon which I run these two types of queries and gives me same result. I want to know which one can perform better as on production there would be millions of searches performed per day.
EDIT - Elasticsearch version is 5.6.1
Aim is to run query like:
SELECT *
FROM MY_INDEX
WHERE (col1 = "val1" OR col2 = "val2")
AND (col3 = "val3" OR col4 = "val4")
By the description of filter context in Elasticsearch guide it seems ES first filters out all records matching your criteria and then executes statements in query context by applying scores. So can anyone tell me which of the below queries can perform better? And what is the theory behind it?
This query using to should clauses within two bool queries
{
"query" : {
"bool" : {
"must" : [
{
"bool" : {
"should" : [
{ "match" : { "col1" : "val1" } },
{ "match" : { "col2" : "val2" } }
]
}
},
{
"bool" : {
"should" : [
{ "match" : { "col3" : "val3" } },
{ "match" : { "col4" : "val4" } }
]
}
}
]
}
}
}
OR this query with a filter clause
{
"query" : {
"bool" : {
"should" : [
{ "match" : { "col1" : "val1" } },
{ "match" : { "col2" : "val2" } }
],
"minimum_should_match" : 1,
"filter" : {
"bool" : {
"should" : [
{ "match" : { "col3" : "val3" } },
{ "match" : { "col4" : "val4" } }
]
}
}
}
}
}