Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between query_string and multi_match?

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?

like image 228
Félix Sanz Avatar asked Jun 07 '16 21:06

Félix Sanz


People also ask

What is multi match query?

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.

How does multi Match work in Elasticsearch?

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 .

How do I search multiple fields in Elasticsearch?

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.


1 Answers

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.

like image 172
pickypg Avatar answered Sep 22 '22 16:09

pickypg