# Performance Comparison between Terms Query and Constant Score Query

**URL:** <https://discuss.elastic.co/t/performance-comparison-between-terms-query-and-constant-score-query/151349>\
**Category:** Elasticsearch\
**Created:** [October 7, 2018, 12:16pm UTC](https://discuss.elastic.co/t/performance-comparison-between-terms-query-and-constant-score-query/151349 "2018-10-07T12:16:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gaurav\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@Gaurav\_Kumar1](https://discuss.elastic.co/u/Gaurav_Kumar1)\
**Post date:** [October 7, 2018, 12:16pm UTC](https://discuss.elastic.co/t/performance-comparison-between-terms-query-and-constant-score-query/151349/1 "2018-10-07T12:16:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![s1monw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/s1monw/32/3637_2.png) [@s1monw](https://discuss.elastic.co/u/s1monw)\
**Post date:** [October 12, 2018, 11:36am UTC](https://discuss.elastic.co/t/performance-comparison-between-terms-query-and-constant-score-query/151349/2 "2018-10-12T11:36:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 9, 2018, 11:36am UTC](https://discuss.elastic.co/t/performance-comparison-between-terms-query-and-constant-score-query/151349/3 "2018-11-09T11:36:03Z")

</div>

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