# Highlight object field, get related field of that object

**URL:** <https://discuss.elastic.co/t/highlight-object-field-get-related-field-of-that-object/179290>\
**Category:** Elasticsearch\
**Created:** [May 2, 2019, 6:58am UTC](https://discuss.elastic.co/t/highlight-object-field-get-related-field-of-that-object/179290 "2019-05-02T06:58:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylvain\_Attoumani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_attoumani/32/45401_2.png) [@Sylvain\_Attoumani](https://discuss.elastic.co/u/Sylvain_Attoumani)\
**Post date:** [May 2, 2019, 6:58am UTC](https://discuss.elastic.co/t/highlight-object-field-get-related-field-of-that-object/179290/1 "2019-05-02T06:58:39Z")

</div>

I'm working with elasticsearch7 and I use highlight in a specific field of an object. My object get 3 attributes :

```
attribute1
attribute2
attribute3

```

attribute1 and attribute2 are just number. But I want to search in my `attribute3` and other field (witch I did), highlight the field attribute3 if my query match (wich I did) but I also want the attribute1 and attribute2 to be in my highlight. Here is an example

```
PUT
 { 
   "title": "title",
   "desc": "this is a test",
   "more_info": [{ 
     "rng": 486513,
     "more" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit,"
   },
     {
      "rng": 145142
     "more": "What is my purpose ? To be an example. oh god"
enter code here
   ]
 }

GET
{
     "query": {
            'bool': {
                   'should' : { [
                          'multi_match' : {
                                'query' : 'dolor sit amet'
                                'fields' : ['title', 'more_info.more']
                           }
                    ]}
             }
       }
       'highlight' : {
             'fields' : {[
                     'more_info': {
                           "fragment_size" => 0,
                           "number_of_fragments" => 1,
                           "no_match_size" => 250,
                           "boundary_scanner" => "sentence"
                      }
              }]
       }
}

```

So with that my result is what I want expect in my highlight I got `Lorem ipsum dolor sit amet, consectetur adipiscing elit` witch is what I want but I also want 486513 somehow somewhere

PS: Keep in mind that I'm working with symfony so I translated from php, it may have some syntax error, but I do have the result that I want, I just don't know how to add the information I want.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 2, 2019, 7:48am UTC](https://discuss.elastic.co/t/highlight-object-field-get-related-field-of-that-object/179290/2 "2019-05-02T07:48:42Z")

</div>

You can't highlight a field that didn't match IMO.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Attoumani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_attoumani/32/45401_2.png) [@Sylvain\_Attoumani](https://discuss.elastic.co/u/Sylvain_Attoumani)\
**Post date:** [May 2, 2019, 9:24am UTC](https://discuss.elastic.co/t/highlight-object-field-get-related-field-of-that-object/179290/3 "2019-05-02T09:24:38Z")

</div>

Damn, so the best way to do this would be to add my rng inside my field and then work with it once I got the result ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 2, 2019, 10:56am UTC](https://discuss.elastic.co/t/highlight-object-field-get-related-field-of-that-object/179290/4 "2019-05-02T10:56:14Z")

</div>

Probably. I don't see why you would highlight which does not match...

---

<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:** [May 30, 2019, 10:56am UTC](https://discuss.elastic.co/t/highlight-object-field-get-related-field-of-that-object/179290/5 "2019-05-30T10:56:26Z")

</div>

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