Query without a constant_score and with constant_score

Hello,

I have the following data set.

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.

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.

Please format your code using </> icon as explained in this guide. 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.

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.

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

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