0
0
Elasticsearchquery~3 mins

Why Dis max query in Elasticsearch? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if your search could instantly find the best match without you doing extra work?

The Scenario

Imagine you want to search a big library catalog where books can be found by title, author, or summary. You try searching each field separately and then manually pick the best match from all results.

The Problem

This manual way is slow and confusing. You have to run many searches and then compare scores yourself. It's easy to miss the best match or give wrong importance to some fields.

The Solution

The Dis max query lets Elasticsearch do this hard work for you. It searches multiple fields at once and picks the best score from them, so you get the most relevant result quickly and correctly.

Before vs After
Before
{ "bool": { "should": [ { "match": { "title": "search term" } }, { "match": { "author": "search term" } }, { "match": { "summary": "search term" } } ] } }
After
{ "dis_max": { "queries": [ { "match": { "title": "search term" } }, { "match": { "author": "search term" } }, { "match": { "summary": "search term" } } ] } }
What It Enables

It enables fast, accurate searches across many fields by focusing on the best match, making your search results smarter and more useful.

Real Life Example

When shopping online, you want to find a product by name, brand, or description. Dis max query helps show you the best matching product no matter which field matches best.

Key Takeaways

Manual searching across fields is slow and error-prone.

Dis max query picks the best score from multiple fields automatically.

This makes search results more relevant and easier to get.