When running this queries:
{
"query_string" : {
"query" : "text",
"fields": ["field1", "field2"]
}
}
-
{
"multi_match" : {
"query" : "text",
"fields": ["field1", "field2"]
}
}
What is the difference? When to use one and when to use the other?
The multi_match query builds on the match query to allow multi-field queries: GET /_search { "query": { "multi_match" : { "query": "this is a test", "fields": [ "subject", "message" ] } } } The query string. The fields to be queried.
Types of multi_match query:edit (default) Finds documents which match any field, but uses the _score from the best field. See best_fields . Finds documents which match any field and combines the _score from each field. See most_fields .
One of the most common queries in elasticsearch is the match query, which works on a single field. And there's another query with the very same options that works also on multiple fields, called multi_match. These queries support text analysis and work really well.
query_string
supports Lucene syntax to interpret the text, where as multi_match
just attempts to match the given "text"
against the listed fields' indexed values.
Query string is therefore far more powerful, but it can also lead to unexpected scenarios, such as where /
may cause part of the string to be interpreted as a regular expression.
DrTech does a pretty excellent job demonstrating the two over in this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With