Highlight from child


(Fei Yao) #1

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


(Maxim Valyanskiy) #2

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


(Fei Yao) #3

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


(Henning Rauch) #4

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.


(Fei Yao) #5

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": {
        "*": { }
    }
}    

}


(system) #6