Peter
Peter

Reputation: 2759

Elasticsearch : Get number of children matched along with parent document

{
                "has_child": {
                    "type": "following",
                    "score_mode": "sum", 
                    "query": {
                        "bool": {
                            "should": [{
                              "match": {
                                "uid": "A"
                              }
                            },{
                              "match": {
                                "uid": "B"
                              }
                            }
                            ]
                        }
                    }
                }
            }

How can I get number of children along with the parent document outputted. I tries inner hits, but that returns the entire child document and might be costly. Can I get only number of children in some efficient way ?

Upvotes: 0

Views: 30

Answers (1)

Taras Kohut
Taras Kohut

Reputation: 2555

Inner hits has a size option:

size

The maximum number of hits to return per inner_hits. By default the top three matching hits are returned.

Set this option to 0 and you will get only number of children ( "total" in response), without the entire documents:

"inner_hits":{"size":0}

Upvotes: 1

Related Questions