Skip to content

Highlighting nested documents with inner_hits and fvh returns no snippets #87185

@scottbessler

Description

@scottbessler

Elasticsearch Version

7.14.1
also tested with 8.2.0 with the same results

Installed Plugins

none

Java Version

bundled

OS Version

Darwin scott.bessler 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000 arm64

Problem Description

When attempting to highlight nested documents using inner_hits, we receive no snippets.

Steps to Reproduce

Create the index

PUT /nestedfvh 
{
  "mappings": {
    "dynamic": "strict",
    "properties": {
      "kvs": {
        "type": "nested",
        "properties": {
          "key": {
            "type": "keyword"
          },
          "value": {
            "type": "text",
            "fields": {
              "exact": {
                "type": "text",
                "term_vector": "with_positions_offsets"
              }
            }
          }
        }
      }
    }
  },
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

add a document

PUT /nestedfvh/_doc/foo
{"kvs": [{"key":"a", "value":"the quick brown fox"}]}

query

POST /nestedfvh/_search
{
  "query": {
    "nested": {
      "path": "kvs",
      "inner_hits": {
        "_source": false,
        "docvalue_fields": [
          "kvs.key"
        ],
        "highlight": {
          "fields": {
            "kvs.value.exact": { "type": "fvh" }
          }
        }
      },
      "query": {
        "bool": {
          "filter": {
            "term": {
              "kvs.key": "a"
            }
          },
          "should": {
            "match_phrase": {
              "kvs.value.exact": "quick brown"
            }
          },
          "minimum_should_match": 1
        }
      }
    }
  }
}

Response is missing snippets for highights:

{
    "statusCode": 200,
    "body": {
        "took": 13,
        "timed_out": false,
        "_shards": {
            "total": 1,
            "successful": 1,
            "skipped": 0,
            "failed": 0
        },
        "hits": {
            "total": {
                "value": 1,
                "relation": "eq"
            },
            "max_score": 0.5753642,
            "hits": [
                {
                    "_index": "nestedfvh",
                    "_type": "_doc",
                    "_id": "foo",
                    "_score": 0.5753642,
                    "_source": {
                        "kvs": [
                            {
                                "key": "a",
                                "value": "the quick brown fox"
                            }
                        ]
                    },
                    "inner_hits": {
                        "kvs": {
                            "hits": {
                                "total": {
                                    "value": 1,
                                    "relation": "eq"
                                },
                                "max_score": 0.5753642,
                                "hits": [
                                    {
                                        "_index": "nestedfvh",
                                        "_type": "_doc",
                                        "_id": "foo",
                                        "_nested": {
                                            "field": "kvs",
                                            "offset": 0
                                        },
                                        "_score": 0.5753642,
                                        "fields": {
                                            "kvs.key": [
                                                "a"
                                            ]
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            ]
        }
    },
    "headers": {
        "x-elastic-product": "Elasticsearch",
        "warning": "299 Elasticsearch-7.14.1-66b55ebfa59c92c15db3f69a335d500018b3331e \"Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.14/security-minimal-setup.html to enable security.\"",
        "content-type": "application/json; charset=UTF-8",
        "content-length": "530"
    },
    "request": {
        "uri": {
            "protocol": "http:",
            "slashes": true,
            "auth": null,
            "host": "localhost:9201",
            "port": "9201",
            "hostname": "localhost",
            "hash": null,
            "search": null,
            "query": null,
            "pathname": "/nestedfvh/_search",
            "path": "/nestedfvh/_search",
            "href": "http://localhost:9201/nestedfvh/_search"
        },
        "method": "POST",
        "headers": {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "User-Agent": "elasticdeveloper",
            "content-length": 577
        }
    },
    "message": "OK",
    "completed": true,
    "environment": {
        "_textTokens": [],
        "_version": {
            "_major": "7",
            "_minor": "14",
            "_patch": "1"
        },
        "_host": "http://localhost:9201",
        "_name": "dev7"
    }
}

If you remove "type": "fvh" it returns an accurate (other than splitting the phrase, :() snippet:

 "highlight": {
      "kvs.value.exact": [
          "the <em>quick</em> <em>brown</em> fox"
      ]
  }

Logs (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions