Performance Comparison between Terms Query and Constant Score Query

Hi All,

We need to just fetch the records by putting a filter condition. Score of query is not relevant to us. Currently we are using terms query as mentioned below:-

GET test/_search
{"query": {"terms": {
  "userId": [123,124]
}}}

We would like to know what would be difference if we replace above query with constant_score query as mentioned below:

GET test/_search
{"query": {"constant_score": {
  "filter": {"terms": {
  "userId": [123,124]
}}
}}}

Will constant_score query give better performance as comparison to simple terms query?

1 Like

no it won't. The reason for this short answer is that TermsQuery rewrites internally to a constant_score query to the executed query will be equivalent.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.