Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Elasticsearch DSL query returning result for condition which isn't true

I want to have three conditions in my elasticsearch query and accordingly I have written as below. But I don’t know why it is returning a DOCUMENT where AMOUNT is 250 and it EXISTS whereas my condition is ATLEAST one of the two i.e. AMOUNT less than or equal to zero or AMOUNT should not exist.

Below is the DSL Query
enter image description here

{
   "from":0,
   "size":10,
   "track_total_hits":true,
   "_source": ["amount", "npa_stageid_loanaccounts"],
   "query":{
      "bool":{
         "must":[
            {
               "query_string":{
                  "default_field":"npa_stageid_loanaccounts.keyword",
                  "query":"Y"
               }
            },
            {
               "bool":{
                  "minimum_should_match":1,
                  "should":[
                     {
                        "range":{
                           "Amount":{
                              "lte":0
                           }
                        }
                     },
                     {
                        "bool":{
                           "must_not":[
                              {
                                 "exists":{
                                    "field":"Amount"
                                 }
                              }
                           ]
                        }
                     }
                  ]
               }
            }
         ]
      }
   }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In your documents, you have amount but in your query you have Amount, the casing is not the same.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading