Skip to content

No highlights returned using dis_max with multi_match queries #25088

@v1r

Description

@v1r

Elasticsearch version: 5.4.0 and 5.4.1
Regression: Yes, works fine in ES 2.x
Plugins installed: []

JVM version: 1.8

OS version : Windows 7

Description of the problem:

No highlights returned when searching using dis_max with a multi_match queries.
Elasticsearch fails with 'null_pointer_exception'

Steps to reproduce:

Create the following index

PUT blog 
{
  "mappings": {
    "blogpost": { 
      "properties": { 
        "title":    { "type": "text", "term_vector": "with_positions_offsets"}, 
        "body":     { "type": "text", "term_vector": "with_positions_offsets"  }
      }
    }
  }
}

Add a new document

PUT blog/blogpost/1
{
  "title": "welcome test",
  "body": "foo"
}

Run the following query to search 'test' string.

GET blog/_search
{
  "query": {
    "bool": {
      "must": {
        "dis_max": {
          "queries": [
            {
              "multi_match": {
                "fields": [
                  "title"
                ], 
                "slop": 0, 
                "type": "phrase_prefix", 
                "max_expansions": 10, 
                "query": "test"
              }
            }, 
            {
              "multi_match": {
                "fields": [
                  "body"
                ], 
                "slop": 0, 
                "type": "phrase_prefix", 
                "max_expansions": 10, 
                "query": "test"
              }
            }]
        }
      }
    }
  },
  "highlight": {
    "fields": {
      "title": {
        "number_of_fragments": 0, 
        "matched_fields": [
          "title",
          "body"
        ], 
        "type": "fvh"
      }
    }, 
    "require_field_match": false
  }
}

Result:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 4,
    "failed": 1,
    "failures": [
      {
        "shard": 3,
        "index": "blog",
        "node": "eMbzhELBQSO9kiRwVss65A",
        "reason": {
          "type": "null_pointer_exception",
          "reason": null
        }
      }
    ]
  },
  "hits": {
    "total": 1,
    "max_score": 0.25811607,
    "hits": []
  }
}

Now, let's update the same document and replace 'foo' with 'test' in the body attribute:

PUT blog/blogpost/1
{
  "title": "welcome test",
  "body": "test"
}

Re-execute the search query above, it will successfully return the result

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "blog",
        "_type": "blogpost",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "title": "welcome test",
          "body": " test"
        },
        "highlight": {
          "title": [
            "w<em>elco</em>me <em>test</em>"
          ]
        }
      }
    ]
  }
}

As you can see, the query will always fail if the document does not find a match in both attributes.

--Cheers!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions