ElasticSearch, multi-match with filter?

后端 未结 4 382
情深已故
情深已故 2021-01-30 08:30

I have a multi-match query in ES, and wish to add a filter.

{
  \"multi_match\" : {
    \"query\" : \"this is a test\",
    \"fields\" : [ \"subject^2\", \"messa         


        
4条回答
  •  粉色の甜心
    2021-01-30 09:33

    As per the new Documentation of Elasticsearch, the format is little bit changed, now you have to use bool and must and can apply filter separately from query like follows,

    {
        'index' : 'users',
            'type' : 'users',
            'body' : {
              "query" : {
                "bool" : {
                  "must" : {
                    'multi_match' : {
                        'fields' : {'source^1', 'first_name^5', 'last_name^4', 'email^3', 'postcode^2', 'telephone', 'address', 'alternate_address'
                        },
                        'query' : 'Shahrukh Anwar',
                    },
                  },
                  "filter" : {
                    "term" : {
                      'assigned_to' : 125
                    }
                  }
                }
              }
            }
    }
    

提交回复
热议问题