Describe the issue:
I’ve run into some unexpected behavior when using the track_scores
option in queries.
When I run a query for a single term that returns a large number of hits, setting track_scores=true
increases the query time as reported by OpenSearch (took
). Since it’s a single term query, the scores are all the same, but I guess increased execution time is to be expected for keeping track of more things.
However, when I query for a large number of terms, the effect is reversed. Setting track_scores=true
makes the query execute faster! This seems counter-intuitive as I wouldn’t expect additional tracking to improve performance. At best I would have expected it to have no impact at all.
I tested this via the OpenSearch dashboard as well as through the java client. For an index with 162 million docs on two shards, tracking scores reduced the query time by about 20%. Tried other test setups as well and the effect was noticeable as well.
Is there any insight into why this might happen? I’m trying to optimize my queries/mappings and some info on this would be useful.
Versions : 1.0
Sample query:
{
"query":{
"terms":{
"some.keyword.field":[
...insert 100 values here
]
}
},
"_source":false,
"sort":[
{
"sort.field":{
"order":"desc"
}
}
]
}