# Nested object retrieval in ElasticSearch query

**URL:** <https://discuss.elastic.co/t/nested-object-retrieval-in-elasticsearch-query/163389>\
**Category:** Elasticsearch\
**Created:** [January 8, 2019, 3:23pm UTC](https://discuss.elastic.co/t/nested-object-retrieval-in-elasticsearch-query/163389 "2019-01-08T15:23:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gn\_dev](https://avatars.discourse-cdn.com/v4/letter/g/8edcca/32.png) [@gn\_dev](https://discuss.elastic.co/u/gn_dev)\
**Post date:** [January 8, 2019, 3:23pm UTC](https://discuss.elastic.co/t/nested-object-retrieval-in-elasticsearch-query/163389/1 "2019-01-08T15:23:46Z")

</div>

Hi, I'm new in ElasticSearch and I have a few questions regarding nested object retrieval when a specific condition is matched.

I have a tree-like structure as follow:

```
{

    "id": 4,
    "sora": [
        {
            "pContext": {
                "context": {
                    "sT": "D3",
                    "uT": "ST"
                },
                "entities": [
                    {
                        "name": "premium",
                        "bName": "premium",
                        "fT": "site",
                        "eT": "F_P",
                        "children": [
                            {
                                "name": "capa",
                                "bName": "capa",
                                "fT": "site",
                                "eT": "FFT",
                                "children": []
                            },
                            {
                                "name": "code",
                                "bName": "Codes",
                                "fT": "site",
                                "eT": "FFT",
                                "children": []
                            },
                            {
                                "name": "selection A",
                                "fT": "site",
                                "eT": "SELECTION_A",
                                "children": [
                                    {
                                        "name": "A1",
                                        "fT": "site",
                                        "eT": "ADD",
                                        "children": []
                                    },
                                    {
                                        "name": "A2",
                                        "fT": "site",
                                        "eT": "ADD",
                                        "children": []
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        },
        {
            "pContext": {
                "context": {
                    "sT": "D2",
                    "uT": "ST"
                },
                "entities": [
                    {
                        "name": "112",
                        "bName": "112",
                        "eT": "D_TYPE",
                        "children": []
                    }
                ]
            }
        }
    ]
}

```

**My mapping:**

```
{
    "mappings": {
        "abc": {
            "properties": {
                "id": {
                    "type": "integer"
                },
                "sora": {
                    "type": "nested",
                    "properties": {
                        "pContext": {
                            "type": "nested",
                            "properties": {
                                "context": {
                                    "type": "nested",
                                    "properties": {
                                        "sT": {
                                            "type": "text"
                                        },
                                        "uT": {
                                            "type": "text"
                                        }
                                    }
                                },
                                "entities": {
                                    "type": "nested",
                                    "properties": {
                                        "name": {
                                            "type": "text"
                                        },
                                        "bName": {
                                            "type": "text"
                                        },
                                        "fT": {
                                            "type": "text"
                                        },
                                        "eT": {
                                            "type": "text"
                                        },
                                        "children": {
                                            "type": "object"                                    
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

```

- What I would like to know is, how can I get the nested object that matches my query and their children. I need the object that matched the must inclusive filter. Is that possible?
- How can I search for a field without specifying the path? E.g: "\*.myfield": "value" and retrieve the nested object that matched it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 5, 2019, 3:24pm UTC](https://discuss.elastic.co/t/nested-object-retrieval-in-elasticsearch-query/163389/3 "2019-02-05T15:24:30Z")

</div>

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