{
"query":
{
"query_string" :
{
"query" : "((name:the_search_phrase) OR (keywords:the_search_phrase)) AND (city:Sydney, Australia)"
}
}
}
New to elasticsearch. Building the JSON as per the documentation here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
The query runs, however, results with city other that Sydney, Australia
are returned too. Why the AND part is not working?
I want the search phrase to match against either or both name, keywords but the city should be strictly Sydney.
What you are doing is a full text query.
city:Sydney, Australia
seems to be a filter query. Like a WHERE clause in a SQL. You are better off using a filter query for that.Look at the boolean query for examples,
Something like this perhaps,