Using Has Parent Query how can I return specific Child

I have a scenario where a Parent "Car" has children "Toyota" & "Honda". If I run the below Has Parent Query it will return all children's of Car but I am looking is there a way to return only a specific children of Car.

GET /_search
{
    "query": {
        "has_parent" : {
            "parent_type" : "Car",
            "query" : {
                "term" : {
                    "origin" : "USA"
                }
            }
        }
    }
}

It helps if you provide sample documents, the index settings/document mapping, and in the case of parent/child relationships, which ES version you're using (a semi-significant change occurred between versions 5.x and 6)

Based on the information provided, to return specific children you'd just need to add addition query clauses:

GET /_search
{
    "query": {
        "bool": {
            "must": [
                {
                    "has_parent" : {
                        "parent_type" : "Car",
                        "query" : {
                            "term" : {
                                "origin" : "USA"
                            }
                        }
                    }
                },
                {
                    "term": {"color": {"value": "red"}}
                }
            ]
        }
    }
}

But perhaps I'm misunderstanding your question.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.