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.
teano
source share