Array with mixed values

I have some "funny" data which looks like this:

{"subsystem":["windows gui",{"major":5,"minor":1}]}

This is a valid JSON string, but it won't go into Elasticsearch.

If I define a dynamic template like

 {"subsystem": {"match":"subsystem","mapping": {"type": "string"}}}


{"index.mapping.ignore_malformed": "true"}

I get an Exception:

MapperParsingException[failed to parse [a.b.c.subsystem]]; nested: IllegalArgumentException[unknown property [major]];

So all I can do is to eliminate this part of my JSON before sending it to Elasticsearch.
However, it would be helpful if Elasticsearch provided a way to handle this type of JSON structure dynamically.

1 Like

If you don't want to index what is under subsystem, you can use enabled.

I have tried out your advice by adding this to dynamic_templates:

{"subsystem": {"match":"subsystem","mapping": {"enabled": "false"}}}

but this seems to be ignored:

MapperParsingException[Merging dynamic updates triggered a conflict: mapper [a.bc.subsystem] of different type, current_type [string], merged_type [ObjectMapper]]

Maybe it does not work with dynamic_templates?

Yes because when dynamic mapping is applied it's already too late.

Don't do that in dynamic mapping. Why do you think you should do that there BTW?

This is because I am using dynamic mapping - my JSONs are deeply nested and some branches vary a lot, so I don't want to go through creating the complete index structure myself.
In any case, I now simply pre-process the JSON before sending it to Elasticsearch, this seems to be the most efficient solution.