elasticsearch - Elastic Search Query using an OR operator inside a bool -


i need build simple query translates condition "age" between 40 - 60 , "country" or in . searching solution using bool operator.

i tried below option:

    "bool": {         "must": [            {                "range": {                   "age": {                      "from": 40,                      "to": 60                   }                }            },            {                "terms": {                   "country": [                      "us",                      "in"                   ]                }             }         ]     } 

but query not giving me result. missing here?

thanks! k

your query looks fine. reason think query not working "coutry" field using default analyzer term lower-cased , stored in index. if expected results below query, suspicion correct. fix it, either can change query 1 i've mentioned below or change mapping make field "country" non-analyzed.

"bool": {     "must": [        {            "range": {               "age": {                  "from": 40,                  "to": 60               }            }        },        {            "terms": {               "country": [                  "us",    <---- note i'm using lower-cased terms                  "in"     <---- note i'm using lower-cased terms               ]            }         }     ] } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -