ElasticSearch, multi-match with filter?
Depending on what you need you have to put the filter in the proper position. You have two options:
Use a top-level filter and apply the filter only to the search results but not to the facets
{
"query" : {
"multi_match" : {
"query" : "this is a test",
"fields" : [ "subject^2", "message" ]
}
},
"filter" : {
"term" : { "username": "slimkicker" }
}
}
Use a filtered query and apply the filter to both the search results and the facets
{
"query" : {
"filtered" : {
"query" : {
"multi_match" : {
"query" : "this is a test",
"fields" : [ "subject^2", "message" ]
}
},
"filter" : {
"term" : { "username": "slimkicker" }
}
}
}
}
With Elasticsearch 5 the syntax has changed to the usage of bool query, e.g.
{
"from" : 0,
"size" : 10,
"sort" : "publishDate",
"query": {
"bool": {
"must" : {
"multi_match" : {
"query": "wedding",
"type": "most_fields",
"fields": [ "title", "text" ]
}
},
"filter": {
"term": {
"locale": "english"
}
}
}
}
}
Documentation can be found here.