A multi_match query searches analyzed terms across several specified fields, letting one search-bar request cover fields such as title, synopsis, and tags. Elasticsearch combines the individual field results into aggregated results and orders them by relevance score. section 10.8 section 2.3.4
Listing 10.14 Searching multiple fields using multi_match
GET books/_search
{
"_source": false, #1
"query": {
"multi_match": { #2
"query": "Java", #3
"fields": [ #4
"title",
"synopsis",
"tags"
]
}
},
"highlight": { #5
"fields": {
"title": {},
"tags": {}
}
}
}
Use this runnable books search to see the query text, field array, disabled source fields, and highlighting configuration together. section 10.8
Search movie fields
GET movies/_search { "query": { "multi_match": { "query": "Lord", "fields": ["synopsis", "title"] } } } The query searches for “Lord” in both movie synopsis and title fields. The same structure supports bookstore searches such as “Java” across title, synopsis, and tags. section 8.7.1 section 10.8
Adjust the request when field importance or result presentation matters:
- Boost a field with caret notation, such as "title^2", so a title match receives more importance than a match in tags. section 10.8.4
- Inspect relevance through each result’s _score; higher scores indicate stronger matches and determine result ordering. section 2.3.4
- Add highlighting for selected fields when search results should show matching text, as in title and tags. section 10.8
