Understanding dis_max query


#1

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

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"
        }
      }
    ]
  }
}

(system) #2

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