0
0
Elasticsearchquery~3 mins

Why Multi-match query in Elasticsearch? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could search many places at once with just one simple question?

The Scenario

Imagine you have a huge library of books and you want to find all books that mention a certain word either in the title, the author name, or the summary. You try searching each field one by one manually.

The Problem

Searching each field separately means you have to write many queries and combine results yourself. This is slow, complicated, and easy to miss matches if you forget a field. It's like looking for a needle in many haystacks one by one.

The Solution

The multi-match query lets you search multiple fields at once with a single query. It automatically checks all the fields you want and finds the best matches, saving time and effort.

Before vs After
Before
GET /books/_search
{
  "query": {
    "bool": {
      "should": [
        { "match": { "title": "magic" } },
        { "match": { "author": "magic" } },
        { "match": { "summary": "magic" } }
      ]
    }
  }
}
After
GET /books/_search
{
  "query": {
    "multi_match": {
      "query": "magic",
      "fields": ["title", "author", "summary"]
    }
  }
}
What It Enables

It makes searching across many fields simple and powerful, helping you find relevant results faster and with less code.

Real Life Example

When shopping online, you want to find products by name, description, or brand all at once. Multi-match query helps the search engine do exactly that behind the scenes.

Key Takeaways

Manual searching across fields is slow and error-prone.

Multi-match query searches many fields in one go.

This saves time and finds better results easily.