elastic/elasticsearch

[Bug] Unexpected behavior when indexing boolean values

Closed this issue · 1 comments

There is inconsistent behavior when saving boolean json values as boolean, or as text. The occurring parse error is cryptic and confusing.

Repro steps (assumming the tweets index doesn't exist):

  1. Insert a first record:
~ $ curl -XPUT 'http://127.0.0.1:9200/tweets/tweet/1' -d '{ "key" : 123123123 }'
{"_index":"tweets","_type":"tweet","_id":"1","_version":2,"created":false}
  1. Insert a boolean as a string
~ $ curl -XPUT 'http://127.0.0.1:9200/tweets/tweet/2' -d '{ "key" : "true" }'
{"error":"MapperParsingException[failed to parse [key]]; nested: NumberFormatException[For input string: \"true\"]; ","status":400}

The error is expected, as auto-mapping has decided that key is a number, not a boolean

  1. Insert a boolean as boolean
~ $ curl -XPUT 'http://127.0.0.1:9200/tweets/tweet/3' -d '{ "key" : true }'
{"error":"MapperParsingException[failed to parse [key]]; nested: JsonParseException[Current token (VALUE_TRUE) not numeric, can not use numeric value accessors\n at [Source: [B@464291b8; line: 1, column: 15]]; ","status":400}

The expected result was supposed to be same as in 2). However, there is a cryptic message instead (which I personally don't understand). Is this a bug, or expected behavior for reasons still unknown to me? (disclaimer: I am new to ElasticSearch)

I think the excepiton is just fine since we are throwing them on a different level. We expect numers or strings that we can parse. If you specify a boolean it fails on the json parser rather than when we try to interpret the number it's fails way earlier.