Parent,child and grandchild data query as nested json


(Joodies) #1

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.


(system) #2

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