Highlighting elasticsearch with nested objects

I have a question on how to highlight nested fields of an object.

View the entry as follows:

_source: { id: 286 translations: [ { id: 568 language: lang1 value: foo1 bar1 } { id: 569 language: lang2 value: foo2 bar2 } ] } 

If the translations.value parameter has an ngram filter, is it possible to highlight matches in a nested object such as this? And what the highlight request will look like.

Thank you very much for your reply.

+7
source share
2 answers

Same problem here. It seems that now there is a way to do this in an elastic search and will not be in the near future.

Developer Shay Banon wrote :

To make a selection based on a subquery, the subdocuments must also be retrieved to highlight it, which is more problematic (and less efficient).

Also :

His explanation was that this would require a considerable memory, since there may be a large number of children. And it looks sincere to me, as adding this feature will violate the basic concept of processing N number of channels at a time.

Thus, the only way is to manually process the query result in your own program to add highlights.

Update

I don’t know about tires or ngram filters, but I found a way to get all the attached documents matching the filters using nested facets and facet filters. You need a separate query to highlight, but it is much faster than browsing through _source, at least in my case.

 {"query": {"match_all":{}}, "facets":{ "matching_translations":{ "nested":"translations", "terms":{"field":"translations.value"}, "facet_filter":{ "bool":{"must":[{"terms":{"translations.value":["foo1"]}}]} } } } } 

You can use facet terms to highlight in your program.

For example: I want to highlight links to attached documents (in jquery):

  setHighlights = function(sdata){ var highlightDocs = []; if(sdata['facets'] && sdata['facets']['docIDs'] && sdata['facets']['doctIDs']['terms'] && sdata['facets']['docIDs']['terms'].length >0){ for(var i in sdata['facets']['docIDs']['terms']){ highlightDocs.push(sdata['facets']['docIDs']['terms'][i]['term']) } } $('li.document_link').each(function(){ if($.inArray($(this).attr('id'),highlightDocs) != -1) { $(this).addClass('document_selected'); } }); 

I hope this helps a bit.

+3
source

You can use force_source ": true in the fields to cause the document to be selected after combining the nested fields.

-one
source

All Articles