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

perform full text elastic search

Currently I am trying to perform full text elastic search using the below query

{
 "query": {
"bool": {
  "must": {
    "match": { "city": "mexico city"}
  }
  
}
}
}

I thought the above query would yield the result containing the exact match "Mexico city", however, I am getting the results that contain just Mexico as well. May I know what is wrong with my elastic query please?

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 :

That is happening because match query by default use OR operator to search. So anyone term match then it will return results.

You can change operator as shown below:

{
  "query": {
    "match": {
      "city": {
        "query": "mexico city",
        "operator": "and"
      }
    }
  }
}

You can use match_phrase if you want to match exact phrase:

{
  "query": {
    "match_phrase": {
      "city": "mexico city"
    }
  }
}

Above query will return document only where mexico city is matching exactly.

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