liveBook · Manning

Disjunction max query

As explained in Elasticsearch in Action, Second Edition

A disjunction max query is an Elasticsearch compound query that returns documents matching one or more subqueries and uses the highest matching score, optionally adjusted by a tie-break contribution.

When a bookstore search checks both a book’s title and synopsis, a disjunction max query lets either field match while ranking each document by its strongest field match. It is written as the compound query dis_max and wraps individual leaf queries. section 10.8.2 section 11.6

Configure the query around the scoring behavior you need:

  • Put each field-specific match query inside the queries array; at least one subquery must match. section 11.6
  • Use the highest matching subquery score as the document’s primary relevance score. section 10.8.2 section 11.6
  • Add tie_breaker when matches in other fields should contribute; Elasticsearch multiplies non-best scores by a value from 0.0 to 1.0 and adds them to the best score. section 10.8.3 section 11.6

Search product fields with a tiebreaker

A product search can favor the strongest match for “smart tv” in type, overview, or product while still rewarding documents matching multiple fields. Set tie_breaker to 0.5 when secondary matches should have a moderate effect. section 11.6

Listing 11.22 The dis_max query in action
GET products/_search
{
  "_source": ["type","overview"], 
  "query": {
    "dis_max": {        #1
      "queries": [{     #2
        "match": {
          "type": "smart tv"
        }
      },
      {
        "match": {
          "overview": "smart tv"
        }
      }]
    }
  }
}

Inspect a runnable products/_search request showing dis_max, multiple match clauses, and selected source fields. section 11.6

Listing 11.23 A dis_max query with a tiebreaker
GET products/_search
{
  "_source": ["type","overview"], 
  "query": {
    "dis_max": {
      "queries": [{
        "match": {
          "type": "smart tv"
        }
      },
      {
        "match": {
          "overview": "smart TV"
        }
      },
      {
        "match": {
          "product": "smart TV"
        }
      }],"tie_breaker": 0.5  
    }
  }
}

Compare the same product search with tie_breaker enabled to see how additional matching fields affect relevance. section 11.6

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines query structure and scoring, including multi_match rewriting and tie-break calculation, but defers broader compound-query treatment.
Examples
Demonstrates book title and synopsis searches plus product searches across type, overview, and product fields.
What it assumes
Assumes familiarity with leaf queries and match-based full-text search while introducing compound-query wrapping and scoring.
What you can do after
Apply it via Elasticsearch Query DSL to build multi-field searches with controlled relevance contributions.
How it connects
Connects match queries, multi_match, best-fields search, compound queries, and relevance scoring.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.