Unable to Index document for array of any data (string, object, array) together

Hi,
I am using ES-7.x, facing issue while indexing document, the data structure is like below

{
"field1": [
"string"
"object"
"array"
]
}

I am using field type "nested" at the time of index creation

Note: If I add the first document like the array of an object and second document is an array of a string, then unable to add the second document.
Also, I have tried with the field type "text" still getting the same error

Please suggest me, how can I add all type of documents in a single field

Unfortunately this is not really supported and will yield all sort of issues. All collections in a document must be of the same type for the entries within it. For instance:

{
  "field1": [ "strings" ],
  "field2": [ "arrays" ],
  "field3": [ "objects" ]
}

Just a note, you can do it if you disable indexing, but then nothing will be searchable or aggrageatable.

One workaround is doing what kibana does for it's objects which is wrapping the value in a object:

[
  { "type": "string", "string": "string_value" },
  { "type": "array', "array": "array_value" }
]

This way you can also index without issues

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