# How to properly define a hashmap in ElasticSearch

**URL:** <https://discuss.elastic.co/t/how-to-properly-define-a-hashmap-in-elasticsearch/29345>\
**Category:** Elasticsearch\
**Created:** [September 15, 2015, 8:38pm UTC](https://discuss.elastic.co/t/how-to-properly-define-a-hashmap-in-elasticsearch/29345 "2015-09-15T20:38:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stam585](https://avatars.discourse-cdn.com/v4/letter/s/f1d935/32.png) [@stam585](https://discuss.elastic.co/u/stam585)\
**Post date:** [September 15, 2015, 8:38pm UTC](https://discuss.elastic.co/t/how-to-properly-define-a-hashmap-in-elasticsearch/29345/1 "2015-09-15T20:38:33Z")

</div>

I am using dynamic mapping in ElasticSearch.

I use it because my index is long and I need to use the template feature in order to avoid updating definitions in multiple places ([My other question here](https://discuss.elastic.co/t/static-mapping-vs-dynamic-mapping-when-using-templates/29094)).

I am sending the following json (Object Zoo) which **contains a HashMap** as an example:

```
Put 127.0.0.1:9200/myIndex/Zoo/10
{
  "id" : 1,
  "Name" : "Madagascar",
  "map" : {
    "1" : {
      "id" : -4944060986111146989,
      "name" : null
    },
    "2" : {
      "id" : 5073063561743125202,
      "name" : null
    },
    "3" : {
      "id" : -1777985506870671559,
      "name" : null
    }
  }
}

```

This creates the following Index

```
{
    "mm3_v2": {
        "mappings": {
            "Zoo": {
                "properties": {
                    "Name": {
                        "type": "string"
                    },
                    "id": {
                        "type": "long"
                    },
                    "map": {
                        "properties": {
                            "1": {
                                "properties": {
                                    "id": {
                                        "type": "long"
                                    }
                                }
                            },
                            "2": {
                                "properties": {
                                    "id": {
                                        "type": "long"
                                    }
                                }
                            },
                            "3": {
                                "properties": {
                                    "id": {
                                        "type": "long"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

```

In this example the inner object in the hashmap is short.  
In real life my hashmap's object can be long.

This can create a huge index files (easily 1M rows) and for each object it repeats exactly the same definition.  
(e.g. when stored in a **List** , the mapping does not repeat itself)

Is there a way to properly define a hashmap in elastic search?

---

<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:** [July 5, 2017, 11:50pm UTC](https://discuss.elastic.co/t/how-to-properly-define-a-hashmap-in-elasticsearch/29345/2 "2017-07-05T23:50:15Z")

</div>


