# Parent,child and grandchild data query as nested json

**URL:** <https://discuss.elastic.co/t/parent-child-and-grandchild-data-query-as-nested-json/74804>\
**Category:** Elasticsearch\
**Created:** [February 12, 2017, 1:17pm UTC](https://discuss.elastic.co/t/parent-child-and-grandchild-data-query-as-nested-json/74804 "2017-02-12T13:17:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joodies](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joodies/32/13630_2.png) [@joodies](https://discuss.elastic.co/u/joodies)\
**Post date:** [February 12, 2017, 1:17pm UTC](https://discuss.elastic.co/t/parent-child-and-grandchild-data-query-as-nested-json/74804/1 "2017-02-12T13:17:13Z")

</div>

I have a mapping as follow,

```
PUT parent_child_grandchild
    {
      "mappings": {
        "gran": {},
        "father": {
          "_parent": {
            "type": "gran" 
          }
        },
        "son": {
          "_parent": {
            "type": "father" 
          }
        }
      }
    }

```

how can i get a nested json result as

```
{
	"gran": {
		"gran_field": "ggg",
		"father": [
			{
				"father_field": "eee",
				"son": [
					{
						"son_field": "dfdfd"
					},
					{
						"son_field": "dfdfd"
					}
				]
			},
			{
				"father_field": "eee",
				"son": {
					"son_field": "dfdfd"
				}
			}
		]
	}
}

```

Looks like inner\_hits can make it.

Thanks.

---

<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:** [March 12, 2017, 1:17pm UTC](https://discuss.elastic.co/t/parent-child-and-grandchild-data-query-as-nested-json/74804/2 "2017-03-12T13:17:18Z")

</div>

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