Highlight nested objects with no position gap

My issue is reasonably close to this highlight-field-type-object-or-custom-highlight.

Given a document:

{
     "id":  1,
     "doc_id": 'adef-2321-321'
     "lines":[
        "I would like Elasticsearch to search",
        "lines and return to me the nested,",
        "objects. bla bla bla bla bla"
     ]
}

I create a mapping with position increment gap of lines set to 0.
If do a match_phrase search on search lines, I'll get this document back.

 { 
    ...,
   'highlight': { 'fields': { 'lines': {} },
 }

 {
   ...., 
   'lines': [
          'I would like Elasticsearch to <em>search</em>', 
          '<em>lines</em> and return to me the nested',
    ]
  }

If I use highlighting as show above, I'll get back the first two lines with tags around my phrase. Super!

What if I would like to get some more metadata (i.e. db identifiers, array indices) around these highlighted values? At the moment, it looks like I'll need to string match the highlighted lines back to the original source. Basically, I would like to add some more context around the highlighted lines.

{
     "id":  1,
     "doc_id": 'adef-2321-321'
     "lines":[
         {
              "text": "I would like Elasticsearch to search",
               "line_idx": 1,
               "line_id": "abc233",
         },
         {
              "text": "lines and return to me the nested",
               "line_idx": 2,
               "line_id": "abc2553",
         },
         {
              "text": "objects. bla bla bla bla bla",
               "line_idx": 3,
               "line_id": "abc2113",
         },
       ]
}

Is it possible for the highlighting to return me back those two highlighted lines with line_idx and line_id? I've tried setting lines as nested and setting the position_increment_gap property of text to 0. Maybe I'm just modelling this data incorrectly?

Any hints would be greatly appreciated!

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