JSON technically allows for duplicate keys - do Elasticsearch documents?

I'm looking for an official answer with regards to whether or not this is supported functionality as opposed to "well.. it seems to work that way.. for now"

A quick example:
{
"make" : "Ford",
"make" : "Totoya",
"make" : "Audi",
"year" : 2018
}

Questions:

  1. Does ES intend for all 3 "make" instances to be properly indexed to allow for ((make == Ford || make ==
    "Audi") && year == 2018) type queries?
  2. Does ES intend for a search matching this document to return all three instances of "make" (with or without storing _source)?

Reference article that initially put me down this path:

And instead of debating whether or not the JSON spec does/does not allow for duplicates, I'd suggest heading over to StackOverflow.

Thank you in advance.

I believe (and hope) that elasticsearch will reject that kind of document.

Does it?

One of the links above provides a fairly well documented example where ES (2.4.5) did allow for duplicate keys.

I can work up prototypes to confirm/deny the behavior across the various ES versions but that would uncover behavior as opposed to the intended/supported behavior.

Thanks again.

Tested in 6.1.3:

DELETE test 
PUT test/doc/1
{
"make" : "Ford",
"make" : "Totoya",
"make" : "Audi",
"year" : 2018
}

Gives:

{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse",
    "caused_by": {
      "type": "json_parse_exception",
      "reason": "Duplicate field 'make'\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@f2e3c3; line: 3, column: 7]"
    }
  },
  "status": 400
}
2 Likes

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