# Nested mapping for map with high cardinality keys

**URL:** <https://discuss.elastic.co/t/nested-mapping-for-map-with-high-cardinality-keys/211707>\
**Category:** Elasticsearch\
**Created:** [December 12, 2019, 6:01pm UTC](https://discuss.elastic.co/t/nested-mapping-for-map-with-high-cardinality-keys/211707 "2019-12-12T18:01:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SuburbanDad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suburbandad/32/59304_2.png) [@SuburbanDad](https://discuss.elastic.co/u/SuburbanDad)\
**Post date:** [December 12, 2019, 6:01pm UTC](https://discuss.elastic.co/t/nested-mapping-for-map-with-high-cardinality-keys/211707/1 "2019-12-12T18:01:24Z")

</div>

I have a difficult json structure I am trying to map and index in elasticsearch. Unfortunately I am not able to restructure this json to make it more palatable for indexing.

The primary challenge is essentially a Map\<UUID, Object\>, .e.g

...  
"simple": "value",  
"number": 5513,  
"someInfos": {  
"D3BAE30D-2548-488F-BA60-5C12B30C1497" : {  
"data" : "I want to index",  
"more" : "predictable struture",  
"etc" : "and so on"  
},  
"D29F6A0B-A765-48F0-A2D6-D5FE8CEF14D6" : {  
"data" : "more stuff to index",  
"youget" : "the idea here"  
}  
}

If I just naively try to index without an explicit mapping, the high cardinality of uuid's in the map causes `Limit of total fields [1000] in index [example] has been exceeded`.

I am currently getting around this problem by setting these maps `"enabled": false`, but I will need these values to be indexed and searchable. Ideally, I would be able to index each of these map entries as nested docs, using the UUID as the doc id for the nested doc.

While searching, I found this topic that sounded promising: [How to map a dynamic map of key values?](https://discuss.elastic.co/t/how-to-map-a-dynamic-map-of-key-values/18030) , but the nested doc link it refers to has been relocated in 7.5.0, and the current docs only make mention of nested ARRAYs of objects, not maps.

Is there a way to accomplish this via mappings or dynamic templates?

TIA.

---

<div class="post-metadata">

**Author:** ![SuburbanDad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suburbandad/32/59304_2.png) [@SuburbanDad](https://discuss.elastic.co/u/SuburbanDad)\
**Post date:** [December 13, 2019, 4:41pm UTC](https://discuss.elastic.co/t/nested-mapping-for-map-with-high-cardinality-keys/211707/2 "2019-12-13T16:41:05Z")

</div>

Bump. Is this just something elasticsearch fundamentally cannot do due to how it stores/flattens keys?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 16, 2019, 9:06am UTC](https://discuss.elastic.co/t/nested-mapping-for-map-with-high-cardinality-keys/211707/3 "2019-12-16T09:06:27Z")

</div>

Using the UUID as a field name is tricky, as you have already encountered. How about a nested array based data structure like

```auto
"someInfos" : [
  {
    "uuid" : "D3BAE30D-2548-488F-BA60-5C12B30C1497",
    ... other fields ...
  },
  {
    "uuid" : "D29F6A0B-A765-48F0-A2D6-D5FE8CEF14D6",
    ... other fields ...
  }
]

```

this way you would not suffer from the field level explosion. One more hint: If you want to search across more than one field within a single array element, you should go with the [nested datatype](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/nested.html)

---

<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:** [January 13, 2020, 9:06am UTC](https://discuss.elastic.co/t/nested-mapping-for-map-with-high-cardinality-keys/211707/4 "2020-01-13T09:06:29Z")

</div>

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