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?
CodePudding user response:
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.