Nested Array in Array


#1

Hello all,

I have to index a json to Elastic which look like the below format. My problem is that the key "variable" is array that contains json objects (I thought about "nested" datatype of Elastic) but some of those objects it's possible to contain nested json arrays inside them. (see variable CUSTOMERS).


POST /example_data/data
{

"process_name": "TEST_PROCESS",
"process_version ": 0,
"process_id": "1111",
"activity_id": "111",
"name": "update_data",
"username": "testUser",
"datetime": "2018-01-01 10:00:00",
"variables": [{
"name": "ΒΑΝΚ",
"data_type": "STRING",
"value": "EUROBANK"
},{
"name": "CITY",
"data_type": "STRING",
"value": "LONDON"
}, {
"name": "CUSTOMERS",
"data_type": "ENTITY",
"value": [{
"variables": [{
"name": "CUSTOMER_NAME",
"data_type": "STRING",
"value": "JOHN"
}, {
"name": " CUSTOMER_CITY",
"data_type": "STRING",
"value": "LONDON"
}
]
}
]
}, {
"name": "CUSTOMERS",
"data_type": "ENTITY",
"value": [{
"variables": [{
"name": "CUSTOMER_NAME",
"data_type": "STRING",
"value": "ΑΘΗΝΑ"
}, {
"name": " CUSTOMER_CITY ",
"data_type": "STRING",
"value": "LIVERPOOL"
}, {
"name": " CUSTOMER_NUMBER",
"data_type": "STRING",
"value": "1234567890"
}

]
}
]
}
] }


When I'm trying to index it I get the following error


{ "error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Can't merge a non object mapping [variables.value] with an object mapping [variables.value]"
}
],
"type": "illegal_argument_exception",
"reason": "Can't merge a non object mapping [variables.value] with an object mapping [variables.value]" }, "status": 400 }


When I remove the variable CUSTOMERS that contains the array, then It works properly because there are only json objects.

Is there a way to handle that?
Thanks in advance,
KT


(Christian Dahlqvist) #2

Each field in the mapping, e.g. value must be mapped to a single type. In your JSON it can be both a string as well as an object, which is not allowed. You will therefore need to restructure your document, e.g. by renaming fields, before you are able to index it into Elasticsearch.


#3

Inside variable with data_type = ENTITY, I changed the key value with entity_value, to avoid conflict. So now value contains text and entity_values contains object.

With this, I was able to index it properly into Elasticsearch


(system) #4

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