Multi-field, multi-word, match without query_string

后端 未结 4 1587
清酒与你
清酒与你 2020-12-23 21:58

I would like to be able to match a multi word search against multiple fields where every word searched is contained in any of the fields, any combination. T

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-23 22:49

    Nowadays you can use cross_fields type in multi_match

    GET /_validate/query?explain
    {
        "query": {
            "multi_match": {
                "query":       "peter smith",
                "type":        "cross_fields", 
                "operator":    "and",
                "fields":      [ "firstname", "lastname", "middlename" ]
            }
        }
    }
    

    Cross-fields take a term-centric approach. It treats all of the fields as one big field, and looks for each term in any field.

    One thing to note though is that if you want it to work optimally, all fields analyzed should have the same analyzer (standard, english, etc.):

    For the cross_fields query type to work optimally, all fields should have the same analyzer. Fields that share an analyzer are grouped together as blended fields.

    If you include fields with a different analysis chain, they will be added to the query in the same way as for best_fields. For instance, if we added the title field to the preceding query (assuming it uses a different analyzer), the explanation would be as follows:

    (+title:peter +title:smith) ( +blended("peter", fields: [first_name, last_name]) +blended("smith", fields: [first_name, last_name]) )

提交回复
热议问题