Searching for same value across multiple fields
The multi_match
query is used to match the same value across multiple fields. When a user searches for biking jacket
, searching just the product_name
field might not find any matches. To widen the search, we should most probably also search the description
field along with the product_name
field. The document that contains both biking
and jacket
is shown here:
{ "product_name": "Men's Water Resistant Jacket", "description": "Provides comfort during biking and hiking", "unit_price": 69.99, "reviews": 5, "release_date": "2017-03-02" }
Scoring based on a single field is pretty straightforward, scoring based on multiple fields gets tricky. We can't use a match query with an operator as the terms biking
and jacket
don't exist in the same field. We need to use a multi_match
query to search across product_name
and description
fields:
#Multi Match GET chapter6/_search { "query": { "multi_match": { "query": "biking jacket", ...