# Exists query with highlighting

**URL:** <https://discuss.elastic.co/t/exists-query-with-highlighting/223526>\
**Category:** Elasticsearch\
**Created:** [March 13, 2020, 2:32pm UTC](https://discuss.elastic.co/t/exists-query-with-highlighting/223526 "2020-03-13T14:32:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jogi\_Michal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogi_michal/32/45613_2.png) [@Jogi\_Michal](https://discuss.elastic.co/u/Jogi_Michal)\
**Post date:** [March 13, 2020, 2:32pm UTC](https://discuss.elastic.co/t/exists-query-with-highlighting/223526/1 "2020-03-13T14:32:58Z")

</div>

Is there a possibility to use elastic search `exists` query with highlights?

What I need achieve is to find all documents with some field and I'm using the `exists` query for this (it works fine) but additionally, I want to have this field to be highlighted.

How can I do this? It seems that highlighting for the `exists` query is not supported. Is there even a sense of using highlights with `exists` query?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 13, 2020, 4:28pm UTC](https://discuss.elastic.co/t/exists-query-with-highlighting/223526/2 "2020-03-13T16:28:05Z")

</div>

can you maybe explain with the help of an example, what exactly you would like to have highlighted if you search for the existence of a field? Side note: you can have a dedicated highlight\_query in the highlight section, that could help you as well here, but depends on your use-case.

---

<div class="post-metadata">

**Author:** ![Jogi\_Michal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jogi_michal/32/45613_2.png) [@Jogi\_Michal](https://discuss.elastic.co/u/Jogi_Michal)\
**Post date:** [March 16, 2020, 6:57am UTC](https://discuss.elastic.co/t/exists-query-with-highlighting/223526/3 "2020-03-16T06:57:31Z")

</div>

The query is quite complicated. I'm searching for fields which has value in field `content.obj_list.hash.value` - and this works fine. But I want to have this whole field to be highlighted.

The response should give me all documents that have field `content.obj_list.hash.value` filled and highlight should give me this whole field to be highlighted - the same as for regexp query `.*` on this field.

I want to avoid using regexp because it's not optimal (I have a very big query and load on ES instance is very big).

Summarising: I want to have a field to be highlighted as for regexp `.*` with the `exists` query but without using regexp in extra `highlight_query`...

```
    {
         'from': 0,
         'query': {
             'bool': {
                 'should': [
                     {
                         'nested': {
                             'inner_hits': {
                                 'highlight': {
                                     'fields': {
                                         'content.obj_list.hash.value': {
                                             'fragment_size': 200
                                         }
                                     },
                                     'order': 'score',
                                     'type': 'plain'
                                 }
                             },
                             'path': 'content.obj_list',
                             'query': {
                                 'bool': {
                                     'should': [
                                         {
                                             'bool': {
                                                 'minimum_should_match': 1,
                                                 'should': [
                                                     {
                                                         'exists': {
                                                             'field': 'content.obj_list.hash.value'
                                                         }
                                                     }
                                                 ]
                                             }
                                         }
                                     ]
                                 }
                             },
                             'score_mode': 'max'
                         }
                     },
                 ]
             }
         },
         'size': 10,
         'sort': ['_score'],
         'timeout': '10s'
        }
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [March 16, 2020, 1:41pm UTC](https://discuss.elastic.co/t/exists-query-with-highlighting/223526/4 "2020-03-16T13:41:14Z")

</div>

Hey,

from an application perspective (and especially from my ES perspective) it sounds easier as if you just highlight manually, by extracting the field from the inner\_hits array? I might be missing something though, which could be easier to see with a fully fledged example.

--Alex

---

<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:** [April 13, 2020, 1:41pm UTC](https://discuss.elastic.co/t/exists-query-with-highlighting/223526/5 "2020-04-13T13:41:23Z")

</div>

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

---

<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:** [April 13, 2020, 1:41pm UTC](https://discuss.elastic.co/t/exists-query-with-highlighting/223526/6 "2020-04-13T13:41:25Z")

</div>



---

<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:** [November 4, 2022, 7:49am UTC](https://discuss.elastic.co/t/exists-query-with-highlighting/223526/7 "2022-11-04T07:49:11Z")

</div>


