# Struggling to define the mapping for nested schema where same element name is used in parent and child

**URL:** <https://discuss.elastic.co/t/struggling-to-define-the-mapping-for-nested-schema-where-same-element-name-is-used-in-parent-and-child/85861>\
**Category:** Elasticsearch\
**Created:** [May 16, 2017, 6:15am UTC](https://discuss.elastic.co/t/struggling-to-define-the-mapping-for-nested-schema-where-same-element-name-is-used-in-parent-and-child/85861 "2017-05-16T06:15:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sujitbehera27](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sujitbehera27](https://discuss.elastic.co/u/sujitbehera27)\
**Post date:** [May 16, 2017, 6:15am UTC](https://discuss.elastic.co/t/struggling-to-define-the-mapping-for-nested-schema-where-same-element-name-is-used-in-parent-and-child/85861/1 "2017-05-16T06:15:16Z")

</div>

I have been trying to define the proper mapping for my json schema. but after trying all possible variable types and other attributes I have not been able to upload my json.  
In my json I have a key "P" which is nested and complex in nature. this element is present in different sibling level objects and exhibits text,array,nested,object .

after my schema gets created when I try to load my json it fails with below error  
$ curl -XPnST '[http://localhost:9200/ridev2/1](http://localhost:9200/ridev2/1)' -d @v22.jso  
{"error":{"root\_cause":[{"type":"illegal\_argument\_exception","reason":"Can't merge a non object mapping [EXPLA.SIDEHED.P] with an object mapping [EXPLA.SIDEHED.P]"}],"type":"illegal\_argument\_exception","reason":"Can't merge a non object mapping [EXPLA.SIDEHED.P] with an object mapping [EXPLA.SIDEHED.P]"},"status":400}Sujits-MacBook-Pro:STABLE sujitbehera$

Not sure what to do if this issues doesn't get resolved I might have to switch to some other text search db to try out. Please help me understanding where am doing wrong.

My mapping json:  
curl -XDELETE 'localhost:9200/ridev2?pretty'  
curl -H 'Content-Type: application/json' -XPUT [http://localhost:9200/ridev2](http://localhost:9200/ridev2) -d '  
{  
"mappings":{  
"title21":{  
"properties":{  
"CFRDOC":{  
"properties":{  
"AMDDATE":{  
"type":"text"  
},  
"FMTR":{  
"properties":{  
"EXPLA":{  
"properties":{  
"PRTPAGE":{  
"type":"object",  
"properties":{  
"_P":{  
"type":"text"  
}  
}  
},  
"SIDEHED":{  
"type":"object",  
"properties":{  
"HD":{  
"type":"object"  
},  
"P":{  
"type":"object",  
"properties":{  
"_":{  
"type":"text"  
},  
"E":{  
"type":"object",  
"properties":{  
"\_":{  
"type":"text"  
},  
"T":{  
"type":"text"  
}  
}  
}  
},  
"type":"object"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}'

The real josn which am uploading :-------  
{  
"EXPLA":{  
"SIDEHED":[  
{  
"HD":{  
"_":"HOW TO USE THE CODE OF FEDERAL REGULATIONS",  
"SOURCE":"HED"  
},  
"P":[  
"The Code of Federal Regulations is...atest version of any given rule.",  
"To det..ent of any given rule."  
]  
},  
{  
"HD":{  
"_":"OMB CONTROL NUMBERS",  
"SOURCE":"HED"  
},  
"P":{  
"_":"The Paperwork Reductio...rdkeeping or reporting requirements.",  
"PRTPAGE":{  
"P":"vi"  
}  
}  
},  
{  
"HD":{  
"_":"“[RESERVED]” TERMINOLOGY",  
"SOURCE":"HED"  
},  
"P":"The term “[Reserved]” is used as a pl...dentally dropped due to a printing or computer error."  
},  
{  
"HD":{  
"_":"CFR INDEXES AND TABULAR GUIDES",  
"SOURCE":"HED"  
},  
"P":[  
{  
"_":"A subject index t...anua...also included in this volume ",  
"E":{  
"_":"Index and Finding Aids.",  
"T":"04"  
},  
"PRTPAGE":{  
"P":"vii"  
}  
},  
"An index to ...” is carried within that volume.",  
"The Fed....ral Register.",  
"A List of C..FR titles."  
]  
},  
{  
"HD":{  
"_":"SALES",  
"SOURCE":"HED"  
},  
"P":"The Government Publishing Office (GPO) ... 979050, St. Louis, MO 63197-9000."  
},  
{  
"HD":{  
"_":"ELECTRONIC SERVICES",  
"SOURCE":"HED"  
},  
"P":[  
{  
"_":"The full text of the C...Phone 202-512-1800, or 866-512-1800 (toll-free). E-mail, ",  
"E":[  
{  
"_":"[www.ofr.gov](http://www.ofr.gov).",  
"T":"03"  
},  
{  
"_":"ContactCenter@gpo.gov.",  
"T":"03"  
}  
]  
},  
{  
"_":"The e-CFR is..rnment Publishing Office. It is available at ",  
"E":{  
"_":"[www.ecfr.gov](http://www.ecfr.gov).",  
"T":"03"  
}  
},  
{  
"E":{  
"\_":"January 1, 2016.",  
"T":"03"  
}  
}  
]  
}  
]  
}  
}  
Need urgent help

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 16, 2017, 6:23am UTC](https://discuss.elastic.co/t/struggling-to-define-the-mapping-for-nested-schema-where-same-element-name-is-used-in-parent-and-child/85861/2 "2017-05-16T06:23:58Z")

</div>

Each field must be mapped to a single type in an index, so if the field P is a string in one place it has to be so throughout the index.

---

<div class="post-metadata">

**Author:** ![sujitbehera27](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sujitbehera27](https://discuss.elastic.co/u/sujitbehera27)\
**Post date:** [May 16, 2017, 6:26am UTC](https://discuss.elastic.co/t/struggling-to-define-the-mapping-for-nested-schema-where-same-element-name-is-used-in-parent-and-child/85861/3 "2017-05-16T06:26:51Z")

</div>

Thanks for replying so quickly. But my input jsons are in that complex format and have different datatypes. What is the best way to handle this kind of scenario. I have around 5000 such jsons and I have just pasted a snippet actually each josn has around 10 such kind of objects.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 16, 2017, 6:30am UTC](https://discuss.elastic.co/t/struggling-to-define-the-mapping-for-nested-schema-where-same-element-name-is-used-in-parent-and-child/85861/4 "2017-05-16T06:30:55Z")

</div>

The JSON will need to be transformed, but in order to find the best way you need to know the data and how it is to be queried. I am not aware of any generally applicable way to resolve this. Renaming fields and adding a type suffix might be one option but it is hard for me to tell how that affects querying.

---

<div class="post-metadata">

**Author:** ![sujitbehera27](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@sujitbehera27](https://discuss.elastic.co/u/sujitbehera27)\
**Post date:** [May 16, 2017, 6:52am UTC](https://discuss.elastic.co/t/struggling-to-define-the-mapping-for-nested-schema-where-same-element-name-is-used-in-parent-and-child/85861/5 "2017-05-16T06:52:45Z")

</div>

Yah I had tried doing that by renaming the element names at different levels like at come places instead of "P" I made it "PP" if its of different type. I had tried ignore\_all as well

---

<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:** [June 13, 2017, 6:57am UTC](https://discuss.elastic.co/t/struggling-to-define-the-mapping-for-nested-schema-where-same-element-name-is-used-in-parent-and-child/85861/6 "2017-06-13T06:57:15Z")

</div>

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