# Problem with Nested Data Inside the Objects Data

**URL:** <https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936>\
**Category:** Elasticsearch\
**Created:** [July 13, 2017, 6:08am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936 "2017-07-13T06:08:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [July 13, 2017, 6:08am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/1 "2017-07-13T06:08:41Z")

</div>

Hi Everyone,  
I have the data which contains object data inside the Nested data.I want to find out the correct mapping for this. If anybody knows about that then please help me to figure out this problem.

Data:  
{  
"version": "2018",  
"title": "ICD-10-CM External Cause of Injuries Index",  
"letter": [  
{  
"title": "A",  
"mainTerm": [  
{  
"title": {  
"#text": [  
"Abandonment",  
" NEC"  
],  
"nemod": "(causing exposure to weather conditions) (with intent to injure or kill)"  
},  
"code": "X58"  
},  
{  
"title": {  
"#text": "Abuse",  
"nemod": "(adult) (child) (mental) (physical) (sexual)"  
},  
"code": "X58"  
},  
{  
"title": {  
"#text": "Accident",  
"nemod": "(to)"  
},  
"code": "X58",  
"term": [  
{  
"-level": "1",  
"title": {  
"#text": "aircraft",  
"nemod": "(in transit) (powered)"  
},  
"seeAlso": "Accident, transport, aircraft",  
"term": {  
"-level": "2",  
"title": "due to, caused by cataclysm",  
"see": "Forces of nature, by type"  
}  
},  
{  
"-level": "1",  
"title": "animal-rider",  
"see": "Accident, transport, animal-rider"  
},  
{  
"-level": "1",  
"title": "animal-drawn vehicle",  
"see": "Accident, transport, animal-drawn vehicle occupant"  
},  
{  
"-level": "1",  
"title": "automobile",  
"see": "Accident, transport, car occupant"  
},  
{  
"-level": "1",  
"title": "bare foot water skiier",  
"code": "V94.4"  
},  
{  
"-level": "1",  
"title": "boat, boating",  
"seeAlso": "Accident, watercraft",  
"term": {  
"-level": "2",  
"title": "striking swimmer",  
"term": [  
{  
"-level": "3",  
"title": "powered",  
"code": "V94.11"  
},  
{  
"-level": "3",  
"title": "unpowered",  
"code": "V94.12"  
}  
]  
}  
}  
]  
}  
]  
}  
]  
}

---

<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:** [July 13, 2017, 7:03am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/2 "2017-07-13T07:03:27Z")

</div>

This can not be indexed as it is into Elasticsearch as the `title` field in different parts of the document is mapped as object as well as string. Each field must have a single mapping.

---

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [July 13, 2017, 7:10am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/3 "2017-07-13T07:10:27Z")

</div>

Please helpful for giving an example like that

---

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [July 13, 2017, 7:14am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/4 "2017-07-13T07:14:08Z")

</div>

Actually I putting the mapping like that but it's not working

Mapping:  
PUT /icd10cmindex  
{  
"mappings" : {  
"icd10" : {  
"properties" : {  
"version": {  
"type": "string"  
},  
"title":{  
"type":"string"  
},  
"letter": {  
"type": "nested",  
"properties": {  
"title": {  
"type": "string"  
},  
"mainTerm": {  
"type": "nested",  
"properties": {  
"code": {  
"type": "string"  
},  
"see": {  
"type": "string"  
},  
"title": {  
"type": "string"  
},  
"title": {  
"type": "object",  
"properties": {  
"#text": {  
"type": "string"  
},  
"nemod": {  
"type": "string"  
},  
"term": {  
"type": "nested",  
"properties": {  
"-level": {  
"type": "long"  
},  
"title": {  
"type": "string"  
},  
"code": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

If you have any idea for this correct mapping then please tell me I am stuck at that point

---

<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:** [July 13, 2017, 7:16am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/5 "2017-07-13T07:16:08Z")

</div>

> [@abhishek5678](#):
>
> "title":{  
> "type":"string"  
> },

> [@abhishek5678](#):
>
> "title": {  
> "type": "object",

You can not have a field mapped two different ways, so you must change the structure of the document to rename one of these fields.

---

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [July 13, 2017, 7:23am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/6 "2017-07-13T07:23:37Z")

</div>

@Christian_Dahlqvist  
I can't change the structure of data.we have to do something Inside these data also.If any other solution then tell me.

---

<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:** [July 13, 2017, 7:25am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/7 "2017-07-13T07:25:29Z")

</div>

No, I can not think of any workaround as this is a fundamental part of how Elasticsearch works.

---

<div class="post-metadata">

**Author:** ![Tetrapack](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Tetrapack](https://discuss.elastic.co/u/Tetrapack)\
**Post date:** [July 13, 2017, 1:55pm UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/8 "2017-07-13T13:55:39Z")

</div>

The idea is not to modify your input data structure. It is to modify the way you index that into Elasticsearch.

Either logstash or custom java/c# indexor could ingest your data to transform them into something with a structure compliant with Elasticsearch constraints.

Here, as christian well told you, the field "title" is mapped as string somewhere and as object somewhere else. Your app to index into elasticsearch should transform one of these field into a field named differently.

---

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [July 14, 2017, 4:24am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/9 "2017-07-14T04:24:30Z")

</div>

I put the mapping like that:  
PUT /icd10cmindex  
{  
"mappings" : {  
"icd10" : {  
"properties" : {  
"version": {  
"type": "string"  
},  
"title":{  
"type":"string"  
},  
"letter": {  
"type": "nested",  
"properties": {  
"title": {  
"type": "string"  
},  
"mainTerm": {  
"type": "nested",  
"properties": {  
"code": {  
"type": "string"  
},  
"see": {  
"type": "string"  
},  
"title": {  
"type": "string"  
},  
"title1": {  
"type": "nested",  
"properties": {  
"#text": {  
"type": "string"  
},  
"nemod": {  
"type": "string"  
},  
"term": {  
"type": "nested",  
"properties": {  
"-level": {  
"type": "long"  
},  
"title": {  
"type": "string"  
},  
"code": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

and I put the query like that:  
GET /icd10cmindex/icd10/\_search  
{  
"\_source": false,  
"query": {  
"nested": {  
"path": "letter.mainTerm.term",  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"letter.mainTerm.term.title": {  
"query": "acute",  
"fuzziness": "AUTO",  
"prefix\_length": 1,  
"analyzer": "standard"  
}  
}  
}  
]  
}  
},  
"inner\_hits": {  
"\_source": {  
"excludes":["title"]  
}  
}

```
    }
}

```

}

and I have the data like that:  
POST /icd10cmindex/icd10/1  
{  
"version": "2018",  
"title": "ICD-10-CM INDEX TO DISEASES and INJURIES",  
"letter": [  
{  
"title": "A",  
"mainTerm": [  
{  
"title": "Aarskog's syndrome",  
"code": "Q87.1"  
},  
{  
"title": "Abandonment",  
"see": "Maltreatment"  
},  
{  
"title1": {  
"#text": "Abasia",  
"nemod": "(-astasia) (hysterical)"  
},  
"code": "F44.4"  
},  
{  
"title1": {  
"#text": "Abderhalden-Kaufmann-Lignac syndrome",  
"nemod": "(cystinosis)"  
},  
"code": "E72.04"  
},  
{  
"title": "Abdomen, abdominal",  
"seeAlso": "condition",  
"term": [  
{  
"-level": "1",  
"title": "acute",  
"code": "R10.0"  
},  
{  
"-level": "1",  
"title": "angina",  
"code": "K55.1"  
},  
{  
"-level": "1",  
"title": "muscle deficiency syndrome",  
"code": "Q79.4"  
}  
]  
}  
]  
}  
]  
}

Actually in my case upto title1 level I am able to get the data but I am not able to get the data with term level so please help me to figure out this problem.

---

<div class="post-metadata">

**Author:** ![abhishek5678](https://avatars.discourse-cdn.com/v4/letter/a/5daacb/32.png) [@abhishek5678](https://discuss.elastic.co/u/abhishek5678)\
**Post date:** [July 17, 2017, 5:36am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/10 "2017-07-17T05:36:34Z")

</div>

Hi Christian\_Dahlqvist,  
I have some nested data. I want to perform the mapping on this data but I am not able to get the correct mapping.  
I have data like that:

Data:  
POST /icd10cmindex/icd10/1  
{  
"version": "2018",  
"title": "ICD-10-CM INDEX TO DISEASES and INJURIES",  
"letter": [  
{  
"title": "A",  
"mainTerm": [  
{  
"title": "Aarskog's syndrome",  
"code": "Q87.1"  
},  
{  
"title": "Abandonment",  
"see": "Maltreatment"  
},  
{  
"title": {  
"#text": "Abasia",  
"nemod": "(-astasia) (hysterical)"  
},  
"code": "F44.4"  
},  
{  
"title": {  
"#text": "Abderhalden-Kaufmann-Lignac syndrome",  
"nemod": "(cystinosis)"  
},  
"code": "E72.04"  
},  
{  
"title": "Abdomen, abdominal",  
"seeAlso": "condition",  
"term": [  
{  
"-level": "1",  
"title": "acute",  
"code": "R10.0"  
},  
{  
"-level": "1",  
"title": "angina",  
"code": "K55.1"  
},  
{  
"-level": "1",  
"title": "muscle deficiency syndrome",  
"code": "Q79.4"  
}  
]  
}  
]  
}  
]  
}

I am applying the mapping like that:  
Mapping:  
PUT /icd10cmindex  
{  
"mappings" : {  
"icd10" : {  
"properties" : {  
"version": {  
"type": "string"  
},  
"title":{  
"type":"string"  
},  
"letter": {  
"type": "nested",  
"properties": {  
"title": {  
"type": "string"  
},  
"mainTerm": {  
"type": "nested",  
"properties": {  
"code": {  
"type": "string"  
},  
"see": {  
"type": "string"  
},  
"title": {  
"type": "string"  
},  
"term": {  
"type": "nested",  
"properties": {  
"-level": {  
"type": "long"  
},  
"title": {  
"type": "string"  
},  
"code": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}  
}

Actually the problem is when I am applying the query then I am not able to get the title field [data.so](http://data.so) provide me the correct mapping for this title field data.

---

<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:** [July 17, 2017, 6:25am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/11 "2017-07-17T06:25:48Z")

</div>

As I stated earlier, that document has a field `title` that in different places is either a string or an object. This is not allowed and can not be mapped.

---

<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:** [August 14, 2017, 6:26am UTC](https://discuss.elastic.co/t/problem-with-nested-data-inside-the-objects-data/92936/12 "2017-08-14T06:26:07Z")

</div>

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