# Query without a constant\_score and with constant\_score

**URL:** <https://discuss.elastic.co/t/query-without-a-constant-score-and-with-constant-score/115413>\
**Category:** Elasticsearch\
**Created:** [January 13, 2018, 4:38pm UTC](https://discuss.elastic.co/t/query-without-a-constant-score-and-with-constant-score/115413 "2018-01-13T16:38:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sibh8](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@sibh8](https://discuss.elastic.co/u/sibh8)\
**Post date:** [January 13, 2018, 4:38pm UTC](https://discuss.elastic.co/t/query-without-a-constant-score-and-with-constant-score/115413/1 "2018-01-13T16:38:34Z")

</div>

Hello,

I have the following data set.

```auto
POST /my_store/products/_bulk
{ "index": { "_id": 1 }}
{ "price" : 10, "productID" : "XHDK-A-1293-#fJ3" }
{ "index": { "_id": 2 }}
{ "price" : 20, "productID" : "KDKE-B-9947-#kL5" }
{ "index": { "_id": 3 }}
{ "price" : 30, "productID" : "JODL-X-1937-#pV7" }
{ "index": { "_id": 4 }}
{ "price" : 30, "productID" : "QQPX-R-3956-#aD8" }

```

What is the difference between the two queries below as both of them returns the same result.

```auto
GET /my_store/products/_search
{
  "query":{
          "bool":{
            "should":[
                {"term":{"price":20}},
                {"term":{ "productID" : "XHDK-A-1293-#fJ3"}}
              ],
            "must_not":{
                "term" : {"price" : 30}
              }
          }
        }
}

GET /my_store/products/_search
{
  "query":{
    "constant_score": {
        "filter": {
          "bool":{
            "should":[
                {"term":{"price":20}},
                {"term":{ "productID" : "XHDK-A-1293-#fJ3"}}
              ],
            "must_not":{
                "term" : {"price" : 30}
              }
          }
        }
    }
  }
}

```

Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 13, 2018, 4:53pm UTC](https://discuss.elastic.co/t/query-without-a-constant-score-and-with-constant-score/115413/2 "2018-01-13T16:53:30Z")

</div>

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```

````

I edited your post.

Most likely you should the difference in the output of those queries. One will have different values for `_score` and the other one has probably a `_score` of `1`.

---

<div class="post-metadata">

**Author:** ![sibh8](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@sibh8](https://discuss.elastic.co/u/sibh8)\
**Post date:** [January 13, 2018, 4:57pm UTC](https://discuss.elastic.co/t/query-without-a-constant-score-and-with-constant-score/115413/3 "2018-01-13T16:57:54Z")

</div>

Thanks for the reply. I am very newbie in Elastic Stack. Would be great if you could help in understanding how does this actually matters. In any of the scenario I am getting 3 records.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 13, 2018, 11:52pm UTC](https://discuss.elastic.co/t/query-without-a-constant-score-and-with-constant-score/115413/4 "2018-01-13T23:52:09Z")

</div>

I think it does not really matter but queries without score computation should be faster.

---

<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:** [February 10, 2018, 11:52pm UTC](https://discuss.elastic.co/t/query-without-a-constant-score-and-with-constant-score/115413/5 "2018-02-10T23:52:48Z")

</div>

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