Why is the bool clause 'must' not used in following

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" }

Corresponding to following SQL statement.

select product
from products
where (price = 20 or productID = 'XHDK-A-1293-#fJ3')
and (price != 30)

I have a DSL query in Elasticsearch.

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}
              }
          }
        }
    }
  }
}

Why have we not used a must between the conditions

"should":[
                {"term":{"price":20}},
                {"term":{ "productID" : "XHDK-A-1293-#fJ3"}}
              ]

and

 "must_not":{
                "term" : {"price" : 30}
              }

Thanks

What is the result you are getting?

Hi,

Thanks for the reply. I am getting an error.

Is it that by default if the operation between 2 conditions is 'must' or is it that must_not is a combination of 'must' and a 'not' of a condition?

Thanks

Can you please share the full error message?

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