Hi
Can someone please help me understand the performance difference between these 2 queries:
#1 Query with 'terms'
{
"query": {
"bool": {
"filter": [
{
"term": {
"service_id": "12345"
}
},
{
"term": {
"name": "hello123"
}
},
{
"terms": {
"date": [1501056000000,1500192000000,1501228800000,1500969600000,1499414400000,1499241600000,1500883200000,1501142400000,1502092800000,1500364800000,1503561600000]
}
}
]
}
},
"size":50
}
#2 Query with 'should'
{
"query": {
"bool": {
"filter": [
{
"term": {
"service_id": "12345"
}
},
{
"term": {
"name": "hello123"
}
},{
"bool":{
"should":[
{
"term": {
"date": 1501315200000
}
},
{
"term": {
"date": 1499846400000
}
},
{
"term": {
"date": 1499328000000
}
},
{
"term": {
"date": 1500710400000
}
},
{
"term": {
"date": 1500796800000
}
},
{
"term": {
"date": 1498982400000
}
},
{
"term": {
"date": 1500883200000
}
},
{
"term": {
"date": 1500624000000
}
},
{
"term": {
"date": 1499155200000
}
}
]
}
}
]} },
"size":50
}
We're running on Elasticsearch 5.4 with a relatively large index,
The 'terms' approach (#1) takes around 4 seconds while the 'should' approach (#2) returns in 40ms!
Obviously I'm randomizing the requested date fields each time so that the results are not cached.
I intuitively thought that #1 should be faster (its alot cleaner to write) ?