Highlight from child

I have a parent-child relationship. I'm able to search out the parent using "has_child" filter or query. Question is how can I get the highlight from the child?

Thanks

Use "inner hits", read about it here: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html

Thanks Maxim. It works beautifully. I'm not sure any performance implication though. :wink:

Hi.

Could you please share your "highlight" -section ? I need highlights on inner_hits as well... but in my case I'm using nested objects instead of a parent-child relationship. Thx.

Cheers, Henning.

Here you are. This is for parent-child and you can modify it for nested.

{
"_source": false,
"query": {
    "bool": {
        "should": [
           {
            "has_child": {
                "type": "extension",
                "query": {
                    "match": {
                       "_all": "united"
                    }
                },
                "inner_hits": {
                    "_source": false,
                    "highlight": {
                        "fields": {
                            "*": { }
                        }
                    }
                }
            }          
           },
           {
            "match": {
               "_all": "Nancy"
            }   
           }
        ]
    }
},
"highlight": {
    "fields": {
        "*": { }
    }
}    

}

1 Like