Parent,child and grandchild data query as nested json

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.

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