Problem with Nested Data Inside the Objects Data

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"
}
]
}
}
]
}
]
}
]
}

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.

Please helpful for giving an example like that

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

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.

@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.

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

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.

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.

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 provide me the correct mapping for this title field data.

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.

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