# Mapping multiple keys to the same name

**URL:** <https://discuss.elastic.co/t/mapping-multiple-keys-to-the-same-name/141572>\
**Category:** Elasticsearch\
**Created:** [July 25, 2018, 12:49pm UTC](https://discuss.elastic.co/t/mapping-multiple-keys-to-the-same-name/141572 "2018-07-25T12:49:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leeleviWib](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@leeleviWib](https://discuss.elastic.co/u/leeleviWib)\
**Post date:** [July 25, 2018, 12:49pm UTC](https://discuss.elastic.co/t/mapping-multiple-keys-to-the-same-name/141572/1 "2018-07-25T12:49:52Z")

</div>

Hi!

We are looking to save a object in key value structure in the elastic and we encounter mapping issues.  
are keys are generated dynamic and we would like them to only be saved once in the mapping to avoid mapping explosion  
"scenes": {  
"key\_a": {  
"in": 1,  
"duration": 2  
},  
"key\_b": {  
"in": 3,  
"duration": 4  
}  
"key\_c": {  
"in": 5,  
"duration": 6  
}  
}

As we are looking at keys that are generated randomly, we would like them all to be mapped to a single key in the mapping i.e "key\_\*".

Dynamic templates doesn't solve our issue as the keys are still being saved separately. We would like to merge all keys to a single key.  
It's worth mentioning that the fields need to be searchable.

Is it possible?

---

<div class="post-metadata">

**Author:** ![shanec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanec/32/4004_2.png) [@shanec](https://discuss.elastic.co/u/shanec)\
**Post date:** [July 25, 2018, 6:42pm UTC](https://discuss.elastic.co/t/mapping-multiple-keys-to-the-same-name/141572/2 "2018-07-25T18:42:03Z")

</div>

The structure will depend a fair bit on what types of searches and aggregations you need to do. For example, you could reformat the data to be something like

```auto
{
  "keyname": "a",
  "in": 3,
  "duration": 2
}

```

As to whether this works for your use case depends on what searches you need to run.

---

<div class="post-metadata">

**Author:** ![leeleviWib](https://avatars.discourse-cdn.com/v4/letter/l/b5ac83/32.png) [@leeleviWib](https://discuss.elastic.co/u/leeleviWib)\
**Post date:** [July 29, 2018, 7:53am UTC](https://discuss.elastic.co/t/mapping-multiple-keys-to-the-same-name/141572/3 "2018-07-29T07:53:50Z")

</div>

thx! we considered the option of changing our object but we wanted to check before if we can use our current structure without causing a mapping explosion.

---

<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:** [August 26, 2018, 7:53am UTC](https://discuss.elastic.co/t/mapping-multiple-keys-to-the-same-name/141572/4 "2018-08-26T07:53:51Z")

</div>

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