Search code examples
jsonelasticsearchelasticsearch-indices

Elastic Search JSON String:JSONObject indexing


can elastic search index values such as

"key": [
            14.0,
            "somestring"
        ]

if i try to ingest this data, i get this error

org.elasticsearch.hadoop.rest.EsHadoopInvalidRequest: Found unrecoverable error [Bad Request(400) - [WriteFailureException; nested: MapperParsingException[failed to parse [FIXMessage.key]]; nested: NumberFormatException[For input string: "somestring"]; ]]; Bailing out..

first, is the above a valid JSON format ? If so, then why is elastic not able to index it?


Solution

  • Elasticsearch is trying to convert "somestring" to number, and failing.

    Your json is valid, and Elasticsearch will happily index multiple values for the same field from an array of values, but they have to all have the same type, and the type must match the type of the corresponding field in the mapping.

    If the field doesn't exist in the mapping, Elasticsearch will create it using a sensible default type based on the first value it sees for that field. So if you tried to index what you posted above, and the "key" field didn't exist, Elasticsearch would create the field, look at the first value it found (14.0) and decide to use the float type. Then it would try to index the second value, "somestring", fail to convert it to a float, and send back an error.

    Make sense?

    You might find this post helpful.