Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch multi_match vs should

Can someone tell me the difference between

"query": {
    "bool": {
        "should": [
            { "match": {"title": keyword} },
            { "match": {"description": keyword} }
        ]
    }

and

"query": {
        "multi_match": {
            "query": keyword,
            "fields": [ "title", "description" ]
        }
    }

Is there any performance turning if choose one of two above?

like image 649
trungnnh Avatar asked Sep 29 '15 08:09

trungnnh


People also ask

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 .

Should must Elasticsearch?

must means: Clauses that must match for the document to be included. should means: If these clauses match, they increase the _score ; otherwise, they have no effect. They are simply used to refine the relevance score for each document. Yes you can use multiple filters inside must .

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.

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.


Video Answer


1 Answers

It depends on the type parameter of your multi_match. In your example, since you didn't specify a type, best_fields is used. That makes use of a Dis Max Query and basically

uses the _score from the best field

On the other hand, your example with should

combines the _score from each field.

and it is equivalent to multi_match with type most_fields

like image 173
Mario Trucco Avatar answered Sep 28 '22 15:09

Mario Trucco