Exists query with highlighting

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.

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.

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'
        }

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

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