Elasticsearch highlighting using multi_match

Viewed 6408

I have used highlighting with ES with simple match query:

GET /_search
{
   "query": {
      "match": {
         "Text": "key words here"
      }
   },
   "highlight": {
      "pre_tags" : ["<span class='highlighter'>"],
      "post_tags" : ["</span>"],
      "fields": {
         "Text": {
            "fragment_size": 400,
            "number_of_fragments": 1,
            "no_match_size" : 20
         }
      }
   }
}

this works nicely and highlight Text is returned in the result with the specified tags.

I would like to use highlighting on a multi_match query like this:

GET /_search
{
   "query": {
      "multi_match": {
         "query": "GB RAM",
         "operator": "AND",
         "fields": "_all"
      }
   },
   "highlight": {
         "pre_tags": [
            "<span class='highlighter'>"
         ],
         "post_tags": [
            "</span>"
         ],
         "fields": {
            "Text": {
               "fragment_size": 400,
               "number_of_fragments": 1,
               "no_match_size": 20
            }
         }
      }
}

this doesn't quite work, the highlight Text returned is 20 chars long (the no_match_size), like this:

 "highlight": {
    "Text": ["        DVD-RAM"]
  }

What am I doing incorrectly here?

2 Answers
Related