# Highlight nested objects with no position gap

**URL:** <https://discuss.elastic.co/t/highlight-nested-objects-with-no-position-gap/164317>\
**Category:** Elasticsearch\
**Created:** [January 15, 2019, 1:45pm UTC](https://discuss.elastic.co/t/highlight-nested-objects-with-no-position-gap/164317 "2019-01-15T13:45:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sean92](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@sean92](https://discuss.elastic.co/u/sean92)\
**Post date:** [January 15, 2019, 1:45pm UTC](https://discuss.elastic.co/t/highlight-nested-objects-with-no-position-gap/164317/1 "2019-01-15T13:45:41Z")

</div>

My issue is reasonably close to this [highlight-field-type-object-or-custom-highlight](https://discuss.elastic.co/t/highlight-field-type-object-or-custom-highlight/51793).

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 12, 2019, 1:45pm UTC](https://discuss.elastic.co/t/highlight-nested-objects-with-no-position-gap/164317/2 "2019-02-12T13:45:44Z")

</div>

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