# Understanding dis\_max query

**URL:** <https://discuss.elastic.co/t/understanding-dis-max-query/148690>\
**Category:** Elasticsearch\
**Created:** [September 15, 2018, 3:23am UTC](https://discuss.elastic.co/t/understanding-dis-max-query/148690 "2018-09-15T03:23:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![keithag](https://avatars.discourse-cdn.com/v4/letter/k/ecb155/32.png) [@keithag](https://discuss.elastic.co/u/keithag)\
**Post date:** [September 15, 2018, 3:23am UTC](https://discuss.elastic.co/t/understanding-dis-max-query/148690/1 "2018-09-15T03:23:38Z")

</div>

I am trying to understand how dis\_max query works by trying the documentation example: [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html)

Specifically, I want to reproduce the documentation which says: "ensure that "albino" matching one field and "elephant" matching another gets a higher score than "albino" matching both fields. To get this result, use both Boolean Query and DisjunctionMax Query."

Here is my corpus:

```
PUT ae1/docs/1
        {
          "title":"albino",
          "body":"elephant"
        }
    PUT ae1/docs/2
        {
          "title":"albino",
          "body":"albino"
        }
```

So, according to the documentation, I want document 1 to rank higher than document 2.

I now understand how it works. The following query works as expected:

```
GET ae1/docs/_search?search_type=dfs_query_then_fetch
    { 
      "query": {
        "bool": {
          "should": [ {
            "dis_max": {
              "tie_breaker": 0.7,
              "boost": 1.2,
              "queries": [
              {"match": {"title": "albino"}},
              {"match": {"body": "albino"}}
              ] } }, {
            "dis_max": {
              "tie_breaker": 0.7,
              "boost": 1.2,
              "queries": [
              {"match": {"title": "elephant"}},
              {"match": {"body": "elephant"}}
              ] } }
          ]
        }
      }
    }
```

The results are:

```
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 1.0505626,
    "hits": [
      {
        "_index": "ae1",
        "_type": "docs",
        "_id": "1",
        "_score": 1.0505626,
        "_source": {
          "title": "albino",
          "body": "elephant"
        }
      },
      {
        "_index": "ae1",
        "_type": "docs",
        "_id": "2",
        "_score": 0.9849268,
        "_source": {
          "title": "albino",
          "body": "albino"
        }
      }
    ]
  }
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 13, 2018, 3:29am UTC](https://discuss.elastic.co/t/understanding-dis-max-query/148690/2 "2018-10-13T03:29:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
