AI Hints
Home›Elasticsearch Tutorial›Phrases and Many Fields
Elasticsearch · Lesson 27 of 120

multi_match

One query, many fields.

⏱ 2 min read▶ Video at 24:48🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

A customer's words could be in the product name, or the brand, or the description. Multi match runs one query across several fields.

  • Name?
  • Brand?
  • Description?

Search three fields

Multi match takes the query, and a list of fields. The caret three on name makes a name match count three times as much. Run it. The boots with summit in their name come first, then products from the Summit brand.

Dev Tools Consoletext
GET products/_search?filter_path=hits.hits._source.name
{
  "query": {
    "multi_match": {
      "query": "summit",
      "fields": ["name^3", "brand", "description"]
    }
  },
  "size": 4
}
Output
{
  "hits": {
    "hits": [
      {"_source": {"name": "Summit Hiking Boots"}},
      {"_source": {"name": "Ultralight 2-Person Tent"}},
      {"_source": {"name": "Arctic Down Sleeping Bag"}},
      {"_source": {"name": "Summer Down Sleeping Bag"}}
    ]
  }
}
Also uses _load
products

multi_match types

Best fields is the default. It scores each document by its single best field. Most fields adds up the scores of every field. And phrase runs a match phrase on each field.

keyvalue
best_fieldsbest single field (default)
most_fieldsadds field scores
phrasematch_phrase per field
^3boost a field

Summary

Multi match searches several fields with one query, and the caret boosts the fields that matter most. Next, exact matches with term.

Key takeaways
  • multi_match
  • fields list
  • ^ boost
Next up: term on Keywords — exact values