# JSON technically allows for duplicate keys - do Elasticsearch documents?

**URL:** <https://discuss.elastic.co/t/json-technically-allows-for-duplicate-keys-do-elasticsearch-documents/118526>\
**Category:** Elasticsearch\
**Created:** [February 5, 2018, 9:21pm UTC](https://discuss.elastic.co/t/json-technically-allows-for-duplicate-keys-do-elasticsearch-documents/118526 "2018-02-05T21:21:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Fraschetti](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@Chris\_Fraschetti](https://discuss.elastic.co/u/Chris_Fraschetti)\
**Post date:** [February 5, 2018, 9:21pm UTC](https://discuss.elastic.co/t/json-technically-allows-for-duplicate-keys-do-elasticsearch-documents/118526/1 "2018-02-05T21:21:52Z")

</div>

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:

> **[Elasticsearch, Kibana and duplicate keys in JSON -](http://www.flax.co.uk/blog/2017/08/03/inconsistent-json-semantics-headache/)**
>
> JSON has been the lingua franca of data exchange for many years. It’s human-readable, lightweight and widely supported. However, the JSON spec does not define what parsers should do when they encounter a duplicate key in an object, e.g.: { "foo": …...

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

> <https://stackoverflow.com/questions/21832701/does-json-syntax-allow-duplicate-keys-in-an-object>

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 5, 2018, 10:03pm UTC](https://discuss.elastic.co/t/json-technically-allows-for-duplicate-keys-do-elasticsearch-documents/118526/2 "2018-02-05T22:03:38Z")

</div>

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

Does it?

---

<div class="post-metadata">

**Author:** ![Chris\_Fraschetti](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@Chris\_Fraschetti](https://discuss.elastic.co/u/Chris_Fraschetti)\
**Post date:** [February 5, 2018, 10:18pm UTC](https://discuss.elastic.co/t/json-technically-allows-for-duplicate-keys-do-elasticsearch-documents/118526/3 "2018-02-05T22:18:32Z")

</div>

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

> **[Elasticsearch, Kibana and duplicate keys in JSON -](http://www.flax.co.uk/blog/2017/08/03/inconsistent-json-semantics-headache/)**
>
> JSON has been the lingua franca of data exchange for many years. It’s human-readable, lightweight and widely supported. However, the JSON spec does not define what parsers should do when they encounter a duplicate key in an object, e.g.: { "foo": …...

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 5, 2018, 10:35pm UTC](https://discuss.elastic.co/t/json-technically-allows-for-duplicate-keys-do-elasticsearch-documents/118526/4 "2018-02-05T22:35:35Z")

</div>

Tested in 6.1.3:

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

```

Gives:

```auto
{
  "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
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 5, 2018, 10:36pm UTC](https://discuss.elastic.co/t/json-technically-allows-for-duplicate-keys-do-elasticsearch-documents/118526/5 "2018-03-05T22:36:04Z")

</div>

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