# Not able to create multiple nested type mapping for hierarchical json data

**URL:** <https://discuss.elastic.co/t/not-able-to-create-multiple-nested-type-mapping-for-hierarchical-json-data/209803>\
**Category:** Elasticsearch\
**Created:** [November 28, 2019, 7:18am UTC](https://discuss.elastic.co/t/not-able-to-create-multiple-nested-type-mapping-for-hierarchical-json-data/209803 "2019-11-28T07:18:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhi\_jeet](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@abhi\_jeet](https://discuss.elastic.co/u/abhi_jeet)\
**Post date:** [November 28, 2019, 7:18am UTC](https://discuss.elastic.co/t/not-able-to-create-multiple-nested-type-mapping-for-hierarchical-json-data/209803/1 "2019-11-28T07:18:32Z")

</div>

I have a json file which contains hierarchical structure. I want to create multiple nested type mapping for this data. When i do it and try to search a field it gives exception in search query.  
Below is the example of json data that I have. I cannot post original data cos its forbidden.  
{  
"elementType" : {  
"type" : "knowledge",  
"entity" : [ { "media" : "book"  
"subject" : [  
{"name" : "maths" ,  
"division" : [  
{"name" : "linear Algebra"},  
{"name" : "calculas"},  
{"name" : "sets"}  
]},  
{"name" : "economics",  
"division" : [  
{"name" : "macro economics"},  
{"name" : "micro economics"}  
]}  
{ "name" : "biology"}  
]},  
{ "media" , "DVD"},  
{ "media", "usb"}

```
			               ]
			 }

```

}

i was able to create nested mapping for entity . I am not able to create nested mapping for subject

var mapping={  
"mappings": {  
"poc": {  
"properties": {  
elementType.entity": {  
"type": "nested"  
}  
}  
}  
}  
}

Need help to create nested mapping for elementType.entity.subject,  
elementType.entity.subject.division. I have taken too many days looking and trying solutions but everything in vein. Please help. If you have any better suggestion feel free to add it. Please note i cannot change my json hierarchy.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [November 28, 2019, 8:08am UTC](https://discuss.elastic.co/t/not-able-to-create-multiple-nested-type-mapping-for-hierarchical-json-data/209803/2 "2019-11-28T08:08:36Z")

</div>

You don’t use the dot notation in the mappings- ‘elementType’ is declared as type nested then you have a ‘properties’ field at the same level to declare the fields it holds eg “entity”.  
Before you do - are you sure you need the overhead of nested docs? If the objects only have one property (“name”) there’s no need for a nested doc. See this [flowchart](https://discuss.elastic.co/t/indexing-hierarchical-couchbase-documents/70400/2)

---

<div class="post-metadata">

**Author:** ![abhi\_jeet](https://avatars.discourse-cdn.com/v4/letter/a/e68b1a/32.png) [@abhi\_jeet](https://discuss.elastic.co/u/abhi_jeet)\
**Post date:** [November 28, 2019, 9:29am UTC](https://discuss.elastic.co/t/not-able-to-create-multiple-nested-type-mapping-for-hierarchical-json-data/209803/4 "2019-11-28T09:29:49Z")

</div>

This is the sample json that i have provided that i have provided. My actual json is very huge. this is just a simulation of the original 1. I will require Nested type cos i will query inner json arrays.. I am ready to live with the overhead. Regarding not to use. operator i wasnt able to follow u. can you post me some example from my json.  
i want to nest elementType.entity & elementType.entity.subject & elementType.entity.subject.division. This are arrays. any help will be appreciated.  
**if I add entity as nested object and perform nested search on elementType.entity.media = knowledge it works fine**. But if i try to add another nested object like elementType.entity.subject the same query used to find media **throws exception "reason": [nested] nested object under path elementType.entity is not of nested type"**

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [November 28, 2019, 10:00am UTC](https://discuss.elastic.co/t/not-able-to-create-multiple-nested-type-mapping-for-hierarchical-json-data/209803/5 "2019-11-28T10:00:19Z")

</div>

> [@Mark\_Harwood](#):
>
> You don’t use the dot notation in the mappings- ‘elementType’ is declared as type nested then you have a ‘properties’ field at the same level to declare the fields it holds eg “entity”.

```
{
  "mappings": {
	"poc": {
	  "properties": {
		"elementType": {
		  "type": "nested",
		  "properties": {
			"entity": {
			  "type": "nested",
			  "properties": {
				"name": {
				  "type": "text"
				}
			  }
			}
		  }
		}
	  }
	}
  }
}

```

---

<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:** [December 26, 2019, 10:00am UTC](https://discuss.elastic.co/t/not-able-to-create-multiple-nested-type-mapping-for-hierarchical-json-data/209803/6 "2019-12-26T10:00:36Z")

</div>

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