# Mapping for Java HashMap

**URL:** <https://discuss.elastic.co/t/mapping-for-java-hashmap/15215>\
**Category:** Elasticsearch\
**Created:** [January 12, 2014, 4:16pm UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215 "2014-01-12T16:16:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Webber](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@Peter\_Webber](https://discuss.elastic.co/u/Peter_Webber)\
**Post date:** [January 12, 2014, 4:16pm UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215/1 "2014-01-12T16:16:40Z")

</div>

I had a look at the mapping ES created automatically for one of my indices,  
and found something that's not quite right:

....  
"annotations" : {  
"properties" : {  
"ids" : {  
"properties" : {  
"hashMap" : {  
"properties" : {  
"N\_10290607" : {  
"type" : "double"  
},  
"A\_1038408" : {  
"type" : "double"  
},  
"A\_11585994" : {  
"type" : "double"  
},  
"B\_1245677" : {  
"type" : "double"  
},  
"B\_1269810" : {  
"type" : "double"  
},  
"C\_15680034" : {  
"type" : "double"  
},  
"N\_1654171" : {  
"type" : "double"  
},  
...

I use Gson to convert Java classes to Json and then directly put them into  
ES. One of the classes I use has a HashMap\<String, Double\> as a central  
piece, where it stores its key-value pairs. It's really just that: the keys  
are stings, the values doubles. ES however creates a mapping for every key  
of the hashmap as you can see above.

Does someone here know what mapping I need to define to avoid that?

Also: Can I change this mapping on the already existing index, or do I have  
to create a new index, then create a mapping, then copy over the data from  
the old index?

Many Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-4329-4edc-b4dc-385a4a38714d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-4329-4edc-b4dc-385a4a38714d%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Oliver\_B\_Fischer](https://avatars.discourse-cdn.com/v4/letter/o/f04885/32.png) [@Oliver\_B\_Fischer](https://discuss.elastic.co/u/Oliver_B_Fischer)\
**Post date:** [January 13, 2014, 10:15am UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215/2 "2014-01-13T10:15:09Z")

</div>

Hi Peter,

ES allows you to defined dynamic mappings there you can determine the  
mapping of a property based on the evaluation of some conditions.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Oliver

Am 12.01.14 17:16, schrieb Peter Webber:

> I had a look at the mapping ES created automatically for one of my  
> indices, and found something that's not quite right:
> 
> ....  
> ||| "annotations"| |: { |  
> |||"properties"| |: { |  
> |||"ids"| |: { |  
> |||"properties"| |: { |  
> |||"hashMap"| |: { |  
> |||"properties"| |: { |  
> |||"N\_10290607"| |: { |  
> |||"type"| |: ||"double"|  
> |||}, |  
> |||"A\_1038408"| |: { |  
> |||"type"| |: ||"double"|  
> |||}, |  
> |||"A\_11585994"| |: { |  
> |||"type"| |: ||"double"|  
> |||}, |  
> |||"B\_1245677"| |: { |  
> |||"type"| |: ||"double"|  
> |||}, |  
> |||"B\_1269810"| |: { |  
> |||"type"| |: ||"double"|  
> |||}, |  
> |||"C\_15680034"| |: { |  
> |||"type"| |: ||"double"|  
> |||}, |  
> |||"N\_1654171"| |: { |  
> |||"type"| |: ||"double"|  
> |||},  
> ...
> 
> I use Gson to convert Java classes to Json and then directly put them  
> into ES. One of the classes I use has a HashMap\<String, Double\> as a  
> central piece, where it stores its key-value pairs. It's really just  
> that: the keys are stings, the values doubles. ES however creates a  
> mapping for every key of the hashmap as you can see above.
> 
> Does someone here know what mapping I need to define to avoid that?
> 
> Also: Can I change this mapping on the already existing index, or do I  
> have to create a new index, then create a mapping, then copy over the  
> data from the old index?
> 
> Many Thanks!  
> |
> 
> --  
> You received this message because you are subscribed to the Google  
> Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send  
> an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-4329-4edc-b4dc-385a4a38714d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-4329-4edc-b4dc-385a4a38714d%40googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/52D3BCAD.5060208%40swe-blog.net](https://groups.google.com/d/msgid/elasticsearch/52D3BCAD.5060208%40swe-blog.net).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [January 14, 2014, 12:01pm UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215/3 "2014-01-14T12:01:22Z")

</div>

Hey Peter,

can you tell me, where your problem with the above approach actually is?  
You feed a number of key/value pairs into elasticsearch, each key and each  
value is evaluated by its type and then put into the mapping, as each key  
becomes an own field in elasticsearch, which can be searched for. Wondering  
why this is a problem for you? Or why do you want to avoid that?

Also, where and how do you want to change the mapping to?

I am a bit confused what and why you are expecting to be different than it  
actually is. Maybe you should not think in java data structures but rather  
in JSON, which is being indexed and needs to create a mapping in order to  
be able to search for it. Happy to help, if I understand what you are  
trying to do. Please elaborate.

--Alex

On Mon, Jan 13, 2014 at 11:15 AM, Oliver B. Fischer  
[mailsink@swe-blog.net](mailto:mailsink@swe-blog.net)wrote:

> Hi Peter,
> 
> ES allows you to defined dynamic mappings there you can determine the  
> mapping of a property based on the evaluation of some conditions.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> reference/current/mapping-dynamic-mapping.html
> 
> Oliver
> 
> Am 12.01.14 17:16, schrieb Peter Webber:
> 
> > I had a look at the mapping ES created automatically for one of my  
> > indices, and found something that's not quite right:
> > 
> > ....  
> > ||| "annotations"| |: { |  
> > |||"properties"| |: { |  
> > |||"ids"| |: { |  
> > |||"properties"| |: { |  
> > |||"hashMap"| |: { |  
> > |||"properties"| |: { |  
> > |||"N\_10290607"| |: { |  
> > |||"type"| |: ||"double"|  
> > |||}, |  
> > |||"A\_1038408"| |: { |  
> > |||"type"| |: ||"double"|  
> > |||}, |  
> > |||"A\_11585994"| |: { |  
> > |||"type"| |: ||"double"|  
> > |||}, |  
> > |||"B\_1245677"| |: { |  
> > |||"type"| |: ||"double"|  
> > |||}, |  
> > |||"B\_1269810"| |: { |  
> > |||"type"| |: ||"double"|  
> > |||}, |  
> > |||"C\_15680034"| |: { |  
> > |||"type"| |: ||"double"|  
> > |||}, |  
> > |||"N\_1654171"| |: { |  
> > |||"type"| |: ||"double"|  
> > |||},  
> > ...
> > 
> > I use Gson to convert Java classes to Json and then directly put them  
> > into ES. One of the classes I use has a HashMap\<String, Double\> as a  
> > central piece, where it stores its key-value pairs. It's really just  
> > that: the keys are stings, the values doubles. ES however creates a  
> > mapping for every key of the hashmap as you can see above.
> > 
> > Does someone here know what mapping I need to define to avoid that?
> > 
> > Also: Can I change this mapping on the already existing index, or do I  
> > have to create a new index, then create a mapping, then copy over the  
> > data from the old index?
> > 
> > Many Thanks!  
> > |
> > 
> > --  
> > You received this message because you are subscribed to the Google  
> > Groups "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send  
> > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-](https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-)  
> > 4329-4edc-b4dc-385a4a38714d%[40googlegroups.com](http://40googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> msgid/elasticsearch/52D3BCAD.5060208%[40swe-blog.net](http://40swe-blog.net).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM\_i9KWgu2ZQmBqSFBeDyMPB2zCfY5Q\_dLrG9-x%2Bh2QFFA%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_i9KWgu2ZQmBqSFBeDyMPB2zCfY5Q_dLrG9-x%2Bh2QFFA%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Peter\_Webber](https://avatars.discourse-cdn.com/v4/letter/p/c77e96/32.png) [@Peter\_Webber](https://discuss.elastic.co/u/Peter_Webber)\
**Post date:** [January 14, 2014, 2:03pm UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215/4 "2014-01-14T14:03:35Z")

</div>

Hi Alex,

thanks for your reply first of all. The problem is that I will have  
millions of keys, and that ES creates a mapping for each. That will bloat  
the mappings data structure and probably lead to some memory and/or  
performance issues somewhere (I don't know enough about ES internals, to  
know precisely where, but it cannot be good to have a few million entries  
in the mapping where one would do.)

Hope that helps!  
Peter

Am Dienstag, 14. Januar 2014 13:01:22 UTC+1 schrieb Alexander Reelsen:

> Hey Peter,
> 
> can you tell me, where your problem with the above approach actually is?  
> You feed a number of key/value pairs into elasticsearch, each key and each  
> value is evaluated by its type and then put into the mapping, as each key  
> becomes an own field in elasticsearch, which can be searched for. Wondering  
> why this is a problem for you? Or why do you want to avoid that?
> 
> Also, where and how do you want to change the mapping to?
> 
> I am a bit confused what and why you are expecting to be different than it  
> actually is. Maybe you should not think in java data structures but rather  
> in JSON, which is being indexed and needs to create a mapping in order to  
> be able to search for it. Happy to help, if I understand what you are  
> trying to do. Please elaborate.
> 
> --Alex
> 
> On Mon, Jan 13, 2014 at 11:15 AM, Oliver B. Fischer \<[mail...@swe-blog.net](mailto:mail...@swe-blog.net)\<javascript:\>
> 
> > wrote:
> 
> > Hi Peter,
> > 
> > ES allows you to defined dynamic mappings there you can determine the  
> > mapping of a property based on the evaluation of some conditions.
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > reference/current/mapping-dynamic-mapping.html
> > 
> > Oliver
> > 
> > Am 12.01.14 17:16, schrieb Peter Webber:
> > 
> > > I had a look at the mapping ES created automatically for one of my  
> > > indices, and found something that's not quite right:
> > > 
> > > ....  
> > > ||| "annotations"| |: { |  
> > > |||"properties"| |: { |  
> > > |||"ids"| |: { |  
> > > |||"properties"| |: { |  
> > > |||"hashMap"| |: { |  
> > > |||"properties"| |: { |  
> > > |||"N\_10290607"| |: { |  
> > > |||"type"| |: ||"double"|  
> > > |||}, |  
> > > |||"A\_1038408"| |: { |  
> > > |||"type"| |: ||"double"|  
> > > |||}, |  
> > > |||"A\_11585994"| |: { |  
> > > |||"type"| |: ||"double"|  
> > > |||}, |  
> > > |||"B\_1245677"| |: { |  
> > > |||"type"| |: ||"double"|  
> > > |||}, |  
> > > |||"B\_1269810"| |: { |  
> > > |||"type"| |: ||"double"|  
> > > |||}, |  
> > > |||"C\_15680034"| |: { |  
> > > |||"type"| |: ||"double"|  
> > > |||}, |  
> > > |||"N\_1654171"| |: { |  
> > > |||"type"| |: ||"double"|  
> > > |||},  
> > > ...
> > > 
> > > I use Gson to convert Java classes to Json and then directly put them  
> > > into ES. One of the classes I use has a HashMap\<String, Double\> as a  
> > > central piece, where it stores its key-value pairs. It's really just  
> > > that: the keys are stings, the values doubles. ES however creates a  
> > > mapping for every key of the hashmap as you can see above.
> > > 
> > > Does someone here know what mapping I need to define to avoid that?
> > > 
> > > Also: Can I change this mapping on the already existing index, or do I  
> > > have to create a new index, then create a mapping, then copy over the  
> > > data from the old index?
> > > 
> > > Many Thanks!  
> > > |
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-](https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-)  
> > > 4329-4edc-b4dc-385a4a38714d%[40googlegroups.com](http://40googlegroups.com).  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > msgid/elasticsearch/52D3BCAD.5060208%[40swe-blog.net](http://40swe-blog.net).
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/d31222dc-8263-4d8f-adac-01ec9ea787cd%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d31222dc-8263-4d8f-adac-01ec9ea787cd%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![sunshine](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@sunshine](https://discuss.elastic.co/u/sunshine)\
**Post date:** [March 12, 2014, 6:37pm UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215/5 "2014-03-12T18:37:53Z")

</div>

Hey Peter,

Did you find a resolution for Hashmap mappings? Looking for the same thing.

Thanks,  
Sangita.

On Tuesday, January 14, 2014 9:03:35 AM UTC-5, Peter Webber wrote:

> Hi Alex,
> 
> thanks for your reply first of all. The problem is that I will have  
> millions of keys, and that ES creates a mapping for each. That will bloat  
> the mappings data structure and probably lead to some memory and/or  
> performance issues somewhere (I don't know enough about ES internals, to  
> know precisely where, but it cannot be good to have a few million entries  
> in the mapping where one would do.)
> 
> Hope that helps!  
> Peter
> 
> Am Dienstag, 14. Januar 2014 13:01:22 UTC+1 schrieb Alexander Reelsen:
> 
> > Hey Peter,
> > 
> > can you tell me, where your problem with the above approach actually is?  
> > You feed a number of key/value pairs into elasticsearch, each key and each  
> > value is evaluated by its type and then put into the mapping, as each key  
> > becomes an own field in elasticsearch, which can be searched for. Wondering  
> > why this is a problem for you? Or why do you want to avoid that?
> > 
> > Also, where and how do you want to change the mapping to?
> > 
> > I am a bit confused what and why you are expecting to be different than  
> > it actually is. Maybe you should not think in java data structures but  
> > rather in JSON, which is being indexed and needs to create a mapping in  
> > order to be able to search for it. Happy to help, if I understand what you  
> > are trying to do. Please elaborate.
> > 
> > --Alex
> > 
> > On Mon, Jan 13, 2014 at 11:15 AM, Oliver B. Fischer \<[mail...@swe-blog.net](mailto:mail...@swe-blog.net)
> > 
> > > wrote:
> > 
> > > Hi Peter,
> > > 
> > > ES allows you to defined dynamic mappings there you can determine the  
> > > mapping of a property based on the evaluation of some conditions.
> > > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/)  
> > > reference/current/mapping-dynamic-mapping.html
> > > 
> > > Oliver
> > > 
> > > Am 12.01.14 17:16, schrieb Peter Webber:
> > > 
> > > > I had a look at the mapping ES created automatically for one of my  
> > > > indices, and found something that's not quite right:
> > > > 
> > > > ....  
> > > > ||| "annotations"| |: { |  
> > > > |||"properties"| |: { |  
> > > > |||"ids"| |: { |  
> > > > |||"properties"| |: { |  
> > > > |||"hashMap"| |: { |  
> > > > |||"properties"| |: { |  
> > > > |||"N\_10290607"| |: { |  
> > > > |||"type"| |: ||"double"|  
> > > > |||}, |  
> > > > |||"A\_1038408"| |: { |  
> > > > |||"type"| |: ||"double"|  
> > > > |||}, |  
> > > > |||"A\_11585994"| |: { |  
> > > > |||"type"| |: ||"double"|  
> > > > |||}, |  
> > > > |||"B\_1245677"| |: { |  
> > > > |||"type"| |: ||"double"|  
> > > > |||}, |  
> > > > |||"B\_1269810"| |: { |  
> > > > |||"type"| |: ||"double"|  
> > > > |||}, |  
> > > > |||"C\_15680034"| |: { |  
> > > > |||"type"| |: ||"double"|  
> > > > |||}, |  
> > > > |||"N\_1654171"| |: { |  
> > > > |||"type"| |: ||"double"|  
> > > > |||},  
> > > > ...
> > > > 
> > > > I use Gson to convert Java classes to Json and then directly put them  
> > > > into ES. One of the classes I use has a HashMap\<String, Double\> as a  
> > > > central piece, where it stores its key-value pairs. It's really just  
> > > > that: the keys are stings, the values doubles. ES however creates a  
> > > > mapping for every key of the hashmap as you can see above.
> > > > 
> > > > Does someone here know what mapping I need to define to avoid that?
> > > > 
> > > > Also: Can I change this mapping on the already existing index, or do I  
> > > > have to create a new index, then create a mapping, then copy over the  
> > > > data from the old index?
> > > > 
> > > > Many Thanks!  
> > > > |
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-](https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-)  
> > > > 4329-4edc-b4dc-385a4a38714d%[40googlegroups.com](http://40googlegroups.com).  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > To view this discussion on the web visit [https://groups.google.com/d/](https://groups.google.com/d/)  
> > > msgid/elasticsearch/52D3BCAD.5060208%[40swe-blog.net](http://40swe-blog.net).
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9fd97086-4547-4c5e-9572-67e02f616582%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9fd97086-4547-4c5e-9572-67e02f616582%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Tomislav\_Poljak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomislav_poljak/32/1177_2.png) [@Tomislav\_Poljak](https://discuss.elastic.co/u/Tomislav_Poljak)\
**Post date:** [March 17, 2014, 9:28am UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215/6 "2014-03-17T09:28:39Z")

</div>

Hi,  
I think first you need to define is what is the requirement (or  
expectation) of hashMap (sub)object in index -\> do you need to search  
on key/value pairs?

Like for example, query = 'hashMap.N\_10290607:XY' ?

If not, if you only need to store json serialization of haspmap as  
part of bigger object inside index (\_source) to retrieve it later, you  
can define not to expand mapping dynamically ("dynamic" : false) in  
the 'hashMap' (sub)object - part of mapping for, like bellow:

...  
"properties" : {  
"hashMap" : {  
"dynamic" : false,  
"properties" : {  
..

This is done by a custom mapping. If you do not define a custom  
mapping elasticsearch will, by default, create and expand mapping for  
hashMap for all keys which will sooner or later create issues in  
index. For more details check

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

If you don't know how to create mapping in the first place you can get  
existing mapping  
([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-mapping.html)),  
remove fields added/recognised by elasticsearch automatically, define  
"dynamic" : false for the 'hashMap' object and use new mapping when  
reindexing data.

Hope this helps,

Tomislav

2014-03-12 19:37 GMT+01:00 [bhagatsangita@gmail.com](mailto:bhagatsangita@gmail.com):

> Hey Peter,
> 
> Did you find a resolution for Hashmap mappings? Looking for the same thing.
> 
> Thanks,  
> Sangita.
> 
> On Tuesday, January 14, 2014 9:03:35 AM UTC-5, Peter Webber wrote:
> 
> > Hi Alex,
> > 
> > thanks for your reply first of all. The problem is that I will have  
> > millions of keys, and that ES creates a mapping for each. That will bloat  
> > the mappings data structure and probably lead to some memory and/or  
> > performance issues somewhere (I don't know enough about ES internals, to  
> > know precisely where, but it cannot be good to have a few million entries in  
> > the mapping where one would do.)
> > 
> > Hope that helps!  
> > Peter
> > 
> > Am Dienstag, 14. Januar 2014 13:01:22 UTC+1 schrieb Alexander Reelsen:
> > 
> > > Hey Peter,
> > > 
> > > can you tell me, where your problem with the above approach actually is?  
> > > You feed a number of key/value pairs into elasticsearch, each key and each  
> > > value is evaluated by its type and then put into the mapping, as each key  
> > > becomes an own field in elasticsearch, which can be searched for. Wondering  
> > > why this is a problem for you? Or why do you want to avoid that?
> > > 
> > > Also, where and how do you want to change the mapping to?
> > > 
> > > I am a bit confused what and why you are expecting to be different than  
> > > it actually is. Maybe you should not think in java data structures but  
> > > rather in JSON, which is being indexed and needs to create a mapping in  
> > > order to be able to search for it. Happy to help, if I understand what you  
> > > are trying to do. Please elaborate.
> > > 
> > > --Alex
> > > 
> > > On Mon, Jan 13, 2014 at 11:15 AM, Oliver B. Fischer  
> > > [mail...@swe-blog.net](mailto:mail...@swe-blog.net) wrote:
> > > 
> > > > Hi Peter,
> > > > 
> > > > ES allows you to defined dynamic mappings there you can determine the  
> > > > mapping of a property based on the evaluation of some conditions.
> > > > 
> > > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html)
> > > > 
> > > > Oliver
> > > > 
> > > > Am 12.01.14 17:16, schrieb Peter Webber:
> > > > 
> > > > > I had a look at the mapping ES created automatically for one of my  
> > > > > indices, and found something that's not quite right:
> > > > > 
> > > > > ....  
> > > > > ||| "annotations"| |: { |  
> > > > > |||"properties"| |: { |  
> > > > > |||"ids"| |: { |  
> > > > > |||"properties"| |: { |  
> > > > > |||"hashMap"| |: { |  
> > > > > |||"properties"| |: { |  
> > > > > |||"N\_10290607"| |: { |  
> > > > > |||"type"| |: ||"double"|  
> > > > > |||}, |  
> > > > > |||"A\_1038408"| |: { |  
> > > > > |||"type"| |: ||"double"|  
> > > > > |||}, |  
> > > > > |||"A\_11585994"| |: { |  
> > > > > |||"type"| |: ||"double"|  
> > > > > |||}, |  
> > > > > |||"B\_1245677"| |: { |  
> > > > > |||"type"| |: ||"double"|  
> > > > > |||}, |  
> > > > > |||"B\_1269810"| |: { |  
> > > > > |||"type"| |: ||"double"|  
> > > > > |||}, |  
> > > > > |||"C\_15680034"| |: { |  
> > > > > |||"type"| |: ||"double"|  
> > > > > |||}, |  
> > > > > |||"N\_1654171"| |: { |  
> > > > > |||"type"| |: ||"double"|  
> > > > > |||},  
> > > > > ...
> > > > > 
> > > > > I use Gson to convert Java classes to Json and then directly put them  
> > > > > into ES. One of the classes I use has a HashMap\<String, Double\> as a  
> > > > > central piece, where it stores its key-value pairs. It's really just  
> > > > > that: the keys are stings, the values doubles. ES however creates a  
> > > > > mapping for every key of the hashmap as you can see above.
> > > > > 
> > > > > Does someone here know what mapping I need to define to avoid that?
> > > > > 
> > > > > Also: Can I change this mapping on the already existing index, or do I  
> > > > > have to create a new index, then create a mapping, then copy over the  
> > > > > data from the old index?
> > > > > 
> > > > > Many Thanks!  
> > > > > |
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > To view this discussion on the web visit
> > > > > 
> > > > > [https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-4329-4edc-b4dc-385a4a38714d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-4329-4edc-b4dc-385a4a38714d%40googlegroups.com).  
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/52D3BCAD.5060208%40swe-blog.net](https://groups.google.com/d/msgid/elasticsearch/52D3BCAD.5060208%40swe-blog.net).
> > > > 
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/9fd97086-4547-4c5e-9572-67e02f616582%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9fd97086-4547-4c5e-9572-67e02f616582%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALuCJxid9RQTN3ESAzA1%2B6%2BnPY6J0ny%3DGVOFzw6un9vaXcek%3Dg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALuCJxid9RQTN3ESAzA1%2B6%2BnPY6J0ny%3DGVOFzw6un9vaXcek%3Dg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![rpras82](https://avatars.discourse-cdn.com/v4/letter/r/97f17d/32.png) [@rpras82](https://discuss.elastic.co/u/rpras82)\
**Post date:** [June 20, 2014, 12:17am UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215/7 "2014-06-20T00:17:46Z")

</div>

Hi,

How would I define a custom mapping if I wanted to index/store only the  
keys in the map and discard the values?

Prasanna

On Monday, March 17, 2014 2:28:39 AM UTC-7, Tomislav Poljak wrote:

> Hi,  
> I think first you need to define is what is the requirement (or  
> expectation) of hashMap (sub)object in index -\> do you need to search  
> on key/value pairs?
> 
> Like for example, query = 'hashMap.N\_10290607:XY' ?
> 
> If not, if you only need to store json serialization of haspmap as  
> part of bigger object inside index (\_source) to retrieve it later, you  
> can define not to expand mapping dynamically ("dynamic" : false) in  
> the 'hashMap' (sub)object - part of mapping for, like bellow:
> 
> ...  
> "properties" : {  
> "hashMap" : {  
> "dynamic" : false,  
> "properties" : {  
> ..
> 
> This is done by a custom mapping. If you do not define a custom  
> mapping elasticsearch will, by default, create and expand mapping for  
> hashMap for all keys which will sooner or later create issues in  
> index. For more details check
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-object-type.html#_dynamic)
> 
> If you don't know how to create mapping in the first place you can get  
> existing mapping  
> (  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-get-mapping.html)),
> 
> remove fields added/recognised by elasticsearch automatically, define  
> "dynamic" : false for the 'hashMap' object and use new mapping when  
> reindexing data.
> 
> Hope this helps,
> 
> Tomislav
> 
> 2014-03-12 19:37 GMT+01:00 \<[bhagat...@gmail.com](mailto:bhagat...@gmail.com) \<javascript:\>\>:
> 
> > Hey Peter,
> > 
> > Did you find a resolution for Hashmap mappings? Looking for the same  
> > thing.
> > 
> > Thanks,  
> > Sangita.
> > 
> > On Tuesday, January 14, 2014 9:03:35 AM UTC-5, Peter Webber wrote:
> > 
> > > Hi Alex,
> > > 
> > > thanks for your reply first of all. The problem is that I will have  
> > > millions of keys, and that ES creates a mapping for each. That will  
> > > bloat  
> > > the mappings data structure and probably lead to some memory and/or  
> > > performance issues somewhere (I don't know enough about ES internals,  
> > > to  
> > > know precisely where, but it cannot be good to have a few million  
> > > entries in  
> > > the mapping where one would do.)
> > > 
> > > Hope that helps!  
> > > Peter
> > > 
> > > Am Dienstag, 14. Januar 2014 13:01:22 UTC+1 schrieb Alexander Reelsen:
> > > 
> > > > Hey Peter,
> > > > 
> > > > can you tell me, where your problem with the above approach actually  
> > > > is?  
> > > > You feed a number of key/value pairs into elasticsearch, each key and  
> > > > each  
> > > > value is evaluated by its type and then put into the mapping, as each  
> > > > key  
> > > > becomes an own field in elasticsearch, which can be searched for.  
> > > > Wondering  
> > > > why this is a problem for you? Or why do you want to avoid that?
> > > > 
> > > > Also, where and how do you want to change the mapping to?
> > > > 
> > > > I am a bit confused what and why you are expecting to be different  
> > > > than  
> > > > it actually is. Maybe you should not think in java data structures but  
> > > > rather in JSON, which is being indexed and needs to create a mapping  
> > > > in  
> > > > order to be able to search for it. Happy to help, if I understand what  
> > > > you  
> > > > are trying to do. Please elaborate.
> > > > 
> > > > --Alex
> > > > 
> > > > On Mon, Jan 13, 2014 at 11:15 AM, Oliver B. Fischer  
> > > > [mail...@swe-blog.net](mailto:mail...@swe-blog.net) wrote:
> > > > 
> > > > > Hi Peter,
> > > > > 
> > > > > ES allows you to defined dynamic mappings there you can determine the  
> > > > > mapping of a property based on the evaluation of some conditions.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-dynamic-mapping.html)
> 
> > > > > Oliver
> > > > > 
> > > > > Am 12.01.14 17:16, schrieb Peter Webber:
> > > > > 
> > > > > > I had a look at the mapping ES created automatically for one of my  
> > > > > > indices, and found something that's not quite right:
> > > > > > 
> > > > > > ....  
> > > > > > ||| "annotations"| |: { |  
> > > > > > |||"properties"| |: { |  
> > > > > > |||"ids"| |: { |  
> > > > > > |||"properties"| |: { |  
> > > > > > |||"hashMap"| |: { |  
> > > > > > |||"properties"| |: { |  
> > > > > > |||"N\_10290607"| |: { |  
> > > > > > |||"type"| |: ||"double"|  
> > > > > > |||}, |  
> > > > > > |||"A\_1038408"| |: { |  
> > > > > > |||"type"| |: ||"double"|  
> > > > > > |||}, |  
> > > > > > |||"A\_11585994"| |: { |  
> > > > > > |||"type"| |: ||"double"|  
> > > > > > |||}, |  
> > > > > > |||"B\_1245677"| |: { |  
> > > > > > |||"type"| |: ||"double"|  
> > > > > > |||}, |  
> > > > > > |||"B\_1269810"| |: { |  
> > > > > > |||"type"| |: ||"double"|  
> > > > > > |||}, |  
> > > > > > |||"C\_15680034"| |: { |  
> > > > > > |||"type"| |: ||"double"|  
> > > > > > |||}, |  
> > > > > > |||"N\_1654171"| |: { |  
> > > > > > |||"type"| |: ||"double"|  
> > > > > > |||},  
> > > > > > ...
> > > > > > 
> > > > > > I use Gson to convert Java classes to Json and then directly put  
> > > > > > them  
> > > > > > into ES. One of the classes I use has a HashMap\<String, Double\> as a  
> > > > > > central piece, where it stores its key-value pairs. It's really just  
> > > > > > that: the keys are stings, the values doubles. ES however creates a  
> > > > > > mapping for every key of the hashmap as you can see above.
> > > > > > 
> > > > > > Does someone here know what mapping I need to define to avoid that?
> > > > > > 
> > > > > > Also: Can I change this mapping on the already existing index, or do  
> > > > > > I  
> > > > > > have to create a new index, then create a mapping, then copy over  
> > > > > > the  
> > > > > > data from the old index?
> > > > > > 
> > > > > > Many Thanks!  
> > > > > > |
> > > > > > 
> > > > > > --  
> > > > > > You received this message because you are subscribed to the Google  
> > > > > > Groups "elasticsearch" group.  
> > > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > > send  
> > > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > > To view this discussion on the web visit
> 
> [https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-4329-4edc-b4dc-385a4a38714d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4cfa6af7-4329-4edc-b4dc-385a4a38714d%40googlegroups.com).
> 
> > > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > > > 
> > > > > --  
> > > > > You received this message because you are subscribed to the Google  
> > > > > Groups "elasticsearch" group.  
> > > > > To unsubscribe from this group and stop receiving emails from it,  
> > > > > send  
> > > > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com).  
> > > > > To view this discussion on the web visit
> 
> [https://groups.google.com/d/msgid/elasticsearch/52D3BCAD.5060208%40swe-blog.net](https://groups.google.com/d/msgid/elasticsearch/52D3BCAD.5060208%40swe-blog.net).
> 
> > > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google  
> > Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send  
> > an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit
> 
> [https://groups.google.com/d/msgid/elasticsearch/9fd97086-4547-4c5e-9572-67e02f616582%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9fd97086-4547-4c5e-9572-67e02f616582%40googlegroups.com).
> 
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/b62e41ed-0ec9-4559-a4f2-0c923306c95d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b62e41ed-0ec9-4559-a4f2-0c923306c95d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:21am UTC](https://discuss.elastic.co/t/mapping-for-java-hashmap/15215/8 "2017-07-06T01:21:03Z")

</div>


