Skip to content

highlight_query doesn't work with nested query and wildcards #26230

@AlexanderOtt85

Description

@AlexanderOtt85

With the following code it is possible to reproduce our issue of highlighting_query with nested query and wildcards in Elasticsearch 5.5.0. In Elasticsearch 2.4.4 we can’t reproduce this issue. The result returns only highlight: “snippet” and not "du.content.content4b.contenttext"

PUT testcase
{
   "settings": {
      "index": {
         "number_of_replicas": 0
      }
   },
   "mappings": {
      "searchdoc": {
         "dynamic_templates": [
            {
               "nested_du_content": {
                  "match": "content4*",
                  "mapping": {
                     "type": "object",
                     "doc_values": false,
                     "properties": {
                        "contenttext": {
                           "type": "string",
                           "copy_to": [
                              "du.content.contenttext"
                           ]
                        }
                     }
                  }
               }
            }
         ],
         "properties": {
            "snippet": {
               "type": "string",
               "doc_values": false
            },
            "du": {
               "dynamic": "strict",
               "type": "nested",
               "include_in_root": "true",
               "properties": {
                  "content": {
                     "type": "nested",
                     "include_in_parent": "true",
                     "dynamic": "true",
                     "properties": {
                        "contenttext": {
                           "type": "string"
                        }
                     }
                  }
               }
            }
         }
      }
   }
}

POST testcase/searchdoc
{
   "snippet": [
      "Bensheim - Auerbach. Das Fürstenlager, ein Landschaftsgarten.",
      "Schwanenteich, am Ufer schwarzer Schwan, im Teich badet Hund Neufundländer",
      "Blumen Engelstrompeten",
      "Gebäude und Anlage Fürstenlager",
      "Quellen, Park Herrenwiese, Hügellandschaft, Tempel, einzelne große alte Bäume, Wein, Eremitage"
   ],
   "du": {
      "content": [
         {
            "content4t": {
               "contenttext": "Bensheim - Auerbach. Das Fürstenlager, ein Landschaftsgarten."
            }
         },
         {
            "content4b": {
               "contenttext": "Schwanenteich, am Ufer schwarzer Schwan, im Teich badet Hund Neufundländer"
            }
         },
         {
            "content4b": {
               "contenttext": "Blumen Engelstrompeten"
            }
         },
         {
            "content4b": {
               "contenttext": "Gebäude und Anlage Fürstenlager"
            }
         },
         {
            "content4b": {
               "contenttext": "Quellen, Park Herrenwiese, Hügellandschaft, Tempel, einzelne große alte Bäume, Wein, Eremitage"
            }
         }
      ]
   }
}

GET testcase/_search
{
   "query": {
      "bool": {
         "must": [
            {
               "match_all": {}
            }
         ]
      }
   },
   "_source": false,
   "highlight": {
      "highlight_query": {
         "bool": {
            "should": [
               {
                  "query_string": {
                     "query": "hund*",
                     "default_field": "snippet"
                  }
               },
               {
                  "nested": {
                     "query": {
                        "query_string": {
                           "query": "hund*",
                           "default_field": "du.content.content4b.contenttext"
                        }
                     },
                     "path": "du.content"
                  }
               }
            ]
         }
      },
      "fields": {
         "maintitle": {},
         "subtitle": {},
         "du.content.*.contenttext": {
            "fragment_size": 50,
            "number_of_fragments": 3
         },
         "snippet": {
            "fragment_size": 50,
            "number_of_fragments": 3
         }
      }
   }
}

Result with Elasticsearch 2.4.4

"hits": {
  "total": 1,
  "max_score": 1,
  "hits": [
     {
        "_index": "hr-sd",
        "_type": "searchdoc",
        "_id": "100010549@2@0@0#0",
        "_score": 1,
        "highlight": {
           "snippet": [
              "Schwanenteich, am Ufer schwarzer Schwan, im Teich badet <em>Hund</em> Neufundländer"
           ],
           "du.content.content4b.contenttext": [
              "Schwanenteich, am Ufer schwarzer Schwan, im Teich badet <em>Hund</em> Neufundländer"
           ]
        }
     }
  ]

Result with Elasticsearch 5.5.0

"hits": [
     {
        "_index": "hr-sd",
        "_type": "searchdoc",
        "_id": "100010549@2@0@0#0",
        "_score": 1,
        "highlight": {
           "snippet": [
              "Schwanenteich, am Ufer schwarzer Schwan, im Teich badet <em>Hund</em> Neufundländer"
           ]
        }
     }
  ]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions