7

I have a question about highlighting nested object fields.

Consider record like this:

_source: {

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

}

If the translations.value has ngram filter, is it possible to highlight matches in nested object such as this one? And how would the highlight query look like.

Thanks a lot for response.

1
  • Hit the same problem today - it tells me I have a highlight (e.g. value: <em>foo2</em> bar2 when I search for foo2) but not simple way of tying that back to the source document Commented Mar 15, 2013 at 4:19

2 Answers 2

3

Same problem over here. It seems that there is now way to do it in elastic search and won't be in near future.

Developer Shay Banon wrote:

In order to do highlighting based on the nested query, the nested documents needs to be extracted as well in order to highlight it, which is more problematic (and less performant).

Also:

His explanation was that this would take a good amount of memory as there can be a large number of children. And it looks genuine to me as adding this feature will violate the basic concept of processing only N number of feeds at a time.

So the only way is to process the result of a query manually in your own programm to add the highlights.

Update

I don't know about tire or ngram filters but i found a way to retrieve all filter matching nested documents by using nested facets and facet filters. You need a seperate query for highlighting but its much faster than browsing through _source, in my case at least.

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

You can use the resulting facet terms for highlighting in your programm.

For example: i want to highlight links to nested 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 that helps a little.

Sign up to request clarification or add additional context in comments.

Comments

-1

You can use force_source" : true in the fields to cause the document be highlighted once nested fields are joined.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.