Performance Comparison between Terms Query and Constant Score Query


(Gaurav Kumar) #1

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?


(Simon Willnauer) #2

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.