# Can you have multiple mappings for a single json object/string?

**URL:** <https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088>\
**Category:** Elasticsearch\
**Created:** [December 17, 2012, 9:21am UTC](https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088 "2012-12-17T09:21:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amy](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@Amy](https://discuss.elastic.co/u/Amy)\
**Post date:** [December 17, 2012, 9:21am UTC](https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088/1 "2012-12-17T09:21:49Z")

</div>

Hi,  
I was wondering if there was a way that a single json object/string could  
have multiple mappings to solve the following problem:

I add one json doc:  
curl localhost:9200/myindex/mytype/1 -d '{"well": {"hi":"there"}}'  
Someone else adds another doc:  
curl localhost:9200/myindex/mytype/2 -d '{"well": "hey"}'  
And they get the following error:  
{"error":"MapperParsingException[object mapping for [mytype] tried to parse  
as object, but got EOF, has a concrete value been provided to  
it?]","status":400}

Moreover, if the documents are uploaded in the other order, "well" is  
mapped as a string, and the term "well.hi" = "there" is not searchable.

This does not happen if the docs have different indexes or types, but I  
don't want to create too many types. Another workaround that I can see is  
to have everyone enter their own unique wrapper for the json. So:  
curl localhost:9200/myindex/mytype/2 -d '{"myuniquewrapper":{"well":  
"hey"}}'  
but it's a bit messy.

Any better ideas?

--

---

<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:** [December 17, 2012, 10:23am UTC](https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088/2 "2012-12-17T10:23:49Z")

</div>

You can not modify core objects once mapping has been defined (or automapping  
just did it for you).

So your first command created a mapping with well defined as an object with a  
String field "hi".  
Second command try to insert a String in place of your object.

But, what do you want to achieve?

Could you consider this kind of structure?

curl localhost:9200/myindex/mytype/1 -d '{"well": ["hi","there"]}'

I don't understand your use case and what is the reason you have to design your  
docs like this.

David.

Le 17 décembre 2012 à 10:21, Amy [amyblarney@gmail.com](mailto:amyblarney@gmail.com) a écrit :

> Hi,  
> I was wondering if there was a way that a single json object/string could  
> have multiple mappings to solve the following problem:
> 
> I add one json doc:  
> curl localhost:9200/myindex/mytype/1 -d '{"well": {"hi":"there"}}'  
> Someone else adds another doc:  
> curl localhost:9200/myindex/mytype/2 -d '{"well": "hey"}'  
> And they get the following error:  
> {"error":"MapperParsingException[object mapping for [mytype] tried to parse  
> as object, but got EOF, has a concrete value been provided to  
> it?]","status":400}
> 
> Moreover, if the documents are uploaded in the other order, "well" is mapped  
> as a string, and the term "well.hi" = "there" is not searchable.
> 
> This does not happen if the docs have different indexes or types, but I don't  
> want to create too many types. Another workaround that I can see is to have  
> everyone enter their own unique wrapper for the json. So:  
> curl localhost:9200/myindex/mytype/2 -d '{"myuniquewrapper":{"well": "hey"}}'  
> but it's a bit messy.
> 
> Any better ideas?
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Amy](https://avatars.discourse-cdn.com/v4/letter/a/4da419/32.png) [@Amy](https://discuss.elastic.co/u/Amy)\
**Post date:** [December 17, 2012, 11:39am UTC](https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088/3 "2012-12-17T11:39:23Z")

</div>

Hi David,  
Thank you for the quick response!  
These json files are from our CMS for our website.  
These start their lives as xml files that contain website content and  
format configuration and are transformed into json and deployed to  
elasticsearch.  
The webserver searches by user type etc, parses the json and serves it up  
on the website.  
We have many different content editors and web developers creating this xml  
(it is generated from forms in our cms, so difficult to change the format).  
Each form is generally created by a different web developer which generates  
a different structure of xml (and then json), so the problem would occur if  
2 different web developers decided to use the field "well" in a different  
way, or if they changed their form but kept the existing json in  
elasticsearch.  
Thanks.

On Monday, December 17, 2012 10:23:49 AM UTC, David Pilato wrote:

> You can not modify core objects once mapping has been defined (or  
> automapping just did it for you).
> 
> So your first command created a mapping with well defined as an object  
> with a String field "hi".  
> Second command try to insert a String in place of your object.
> 
> But, what do you want to achieve?
> 
> Could you consider this kind of structure?
> 
> curl localhost:9200/myindex/mytype/1 -d '{"well": ["hi","there"]}'
> 
> I don't understand your use case and what is the reason you have to  
> design your docs like this.
> 
> David.
> 
> Le 17 décembre 2012 à 10:21, Amy \<[amybl...@gmail.com](mailto:amybl...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi,  
> I was wondering if there was a way that a single json object/string could  
> have multiple mappings to solve the following problem:
> 
> I add one json doc:  
> curl localhost:9200/myindex/mytype/1 -d '{"well": {"hi":"there"}}'  
> Someone else adds another doc:  
> curl localhost:9200/myindex/mytype/2 -d '{"well": "hey"}'  
> And they get the following error:  
> {"error":"MapperParsingException[object mapping for [mytype] tried to  
> parse as object, but got EOF, has a concrete value been provided to  
> it?]","status":400}
> 
> Moreover, if the documents are uploaded in the other order, "well" is  
> mapped as a string, and the term "well.hi" = "there" is not searchable.
> 
> This does not happen if the docs have different indexes or types, but I  
> don't want to create too many types. Another workaround that I can see is  
> to have everyone enter their own unique wrapper for the json. So:  
> curl localhost:9200/myindex/mytype/2 -d '{"myuniquewrapper":{"well":  
> "hey"}}'  
> but it's a bit messy.
> 
> Any better ideas?
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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:** [December 17, 2012, 11:59am UTC](https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088/4 "2012-12-17T11:59:56Z")

</div>

Perhaps you can design your system with a type by developper?

The problem is that you can't mute a field from an object to a String or from a  
String to a Date.

Can't you handle it when your XML file is converted in JSON before it's sent to  
Elasticsearch?

Sorry if I can't help you more...

David.

Le 17 décembre 2012 à 12:39, Amy [amyblarney@gmail.com](mailto:amyblarney@gmail.com) a écrit :

> Hi David,  
> Thank you for the quick response!  
> These json files are from our CMS for our website.  
> These start their lives as xml files that contain website content and format  
> configuration and are transformed into json and deployed to elasticsearch.  
> The webserver searches by user type etc, parses the json and serves it up on  
> the website.  
> We have many different content editors and web developers creating this xml  
> (it is generated from forms in our cms, so difficult to change the format).  
> Each form is generally created by a different web developer which generates a  
> different structure of xml (and then json), so the problem would occur if 2  
> different web developers decided to use the field "well" in a different way,  
> or if they changed their form but kept the existing json in elasticsearch.  
> Thanks.
> 
> On Monday, December 17, 2012 10:23:49 AM UTC, David Pilato wrote:
> 
> > > You can not modify core objects once mapping has been defined (or  
> > > automapping just did it for you).
> > 
> > So your first command created a mapping with well defined as an object  
> > with a String field "hi".  
> > Second command try to insert a String in place of your object.
> > 
> > But, what do you want to achieve?
> > 
> > Could you consider this kind of structure?
> > 
> > curl localhost:9200/myindex/mytype/1 -d '{"well": ["hi","there"]}'
> > 
> > I don't understand your use case and what is the reason you have to  
> > design your docs like this.
> > 
> > David.
> > 
> > Le 17 décembre 2012 à 10:21, Amy \< [amybl...@gmail.com](mailto:amybl...@gmail.com)\> a écrit :
> > 
> > ```
> > > > > Hi,
> > 
> > ```
> > 
> > > ```
> > > I was wondering if there was a way that a single json object/string
> > > 
> > > ```
> > > 
> > > could have multiple mappings to solve the following problem:
> > > 
> > > ```
> > > I add one json doc:
> > > curl localhost:9200/myindex/mytype/1 -d '{"well": {"hi":"there"}}'
> > > Someone else adds another doc:
> > > curl localhost:9200/myindex/mytype/2 -d '{"well": "hey"}'
> > > And they get the following error:
> > > {"error":"MapperParsingException[object mapping for [mytype] tried to
> > > 
> > > ```
> > > 
> > > parse as object, but got EOF, has a concrete value been provided to  
> > > it?]","status":400}
> > > 
> > > ```
> > > Moreover, if the documents are uploaded in the other order, "well" is
> > > 
> > > ```
> > > 
> > > mapped as a string, and the term "well.hi" = "there" is not searchable.
> > > 
> > > ```
> > > This does not happen if the docs have different indexes or types, but
> > > 
> > > ```
> > > 
> > > I don't want to create too many types. Another workaround that I can see  
> > > is to have everyone enter their own unique wrapper for the json. So:  
> > > curl localhost:9200/myindex/mytype/2 -d '{"myuniquewrapper":{"well":  
> > > "hey"}}'  
> > > but it's a bit messy.
> > > 
> > > ```
> > > Any better ideas?
> > > 
> > > --
> > > 
> > > --
> > > David Pilato
> > > http://www.scrutmydocs.org/ <http://www.scrutmydocs.org/>
> > > http://dev.david.pilato.fr/ <http://dev.david.pilato.fr/>
> > > Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> > > 
> > > --
> > > 
> > > ```
> > > 
> > > > >

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [December 17, 2012, 6:24pm UTC](https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088/5 "2012-12-17T18:24:57Z")

</div>

I agree with David, type by developer is feasible approach here if you  
don't have too many developers.

Another approach is to add suffix to field names that would correspond to  
field types. This way your example would become:

curl localhost:9200/myindex/mytype/1 -d '{"well\_obj": {"hi\_str":"there"}}'  
curl localhost:9200/myindex/mytype/2 -d '{"well\_str": "hey"}'

You can even control how newly added fields are mapped using  
dynamic\_templates[http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)  
.

On Monday, December 17, 2012 3:59:56 AM UTC-8, David Pilato wrote:

> Perhaps you can design your system with a type by developper?
> 
> The problem is that you can't mute a field from an object to a String or  
> from a String to a Date.
> 
> Can't you handle it when your XML file is converted in JSON before it's  
> sent to Elasticsearch?
> 
> Sorry if I can't help you more...
> 
> David.
> 
> Le 17 décembre 2012 à 12:39, Amy \<[amybl...@gmail.com](mailto:amybl...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi David,  
> Thank you for the quick response!  
> These json files are from our CMS for our website.  
> These start their lives as xml files that contain website content and  
> format configuration and are transformed into json and deployed to  
> elasticsearch.  
> The webserver searches by user type etc, parses the json and serves it up  
> on the website.  
> We have many different content editors and web developers creating this  
> xml (it is generated from forms in our cms, so difficult to change the  
> format). Each form is generally created by a different web developer which  
> generates a different structure of xml (and then json), so the problem  
> would occur if 2 different web developers decided to use the field "well"  
> in a different way, or if they changed their form but kept the existing  
> json in elasticsearch.  
> Thanks.
> 
> On Monday, December 17, 2012 10:23:49 AM UTC, David Pilato wrote:
> 
> You can not modify core objects once mapping has been defined (or  
> automapping just did it for you).
> 
> So your first command created a mapping with well defined as an object  
> with a String field "hi".  
> Second command try to insert a String in place of your object.
> 
> But, what do you want to achieve?
> 
> Could you consider this kind of structure?
> 
> curl localhost:9200/myindex/mytype/1 -d '{"well": ["hi","there"]}'
> 
> I don't understand your use case and what is the reason you have to  
> design your docs like this.
> 
> David.
> 
> Le 17 décembre 2012 à 10:21, Amy \< [amybl...@gmail.com](mailto:amybl...@gmail.com)\> a écrit :
> 
> Hi,  
> I was wondering if there was a way that a single json object/string could  
> have multiple mappings to solve the following problem:
> 
> I add one json doc:  
> curl localhost:9200/myindex/mytype/1 -d '{"well": {"hi":"there"}}'  
> Someone else adds another doc:  
> curl localhost:9200/myindex/mytype/2 -d '{"well": "hey"}'  
> And they get the following error:  
> {"error":"MapperParsingException[object mapping for [mytype] tried to  
> parse as object, but got EOF, has a concrete value been provided to  
> it?]","status":400}
> 
> Moreover, if the documents are uploaded in the other order, "well" is  
> mapped as a string, and the term "well.hi" = "there" is not searchable.
> 
> This does not happen if the docs have different indexes or types, but I  
> don't want to create too many types. Another workaround that I can see is  
> to have everyone enter their own unique wrapper for the json. So:  
> curl localhost:9200/myindex/mytype/2 -d '{"myuniquewrapper":{"well":  
> "hey"}}'  
> but it's a bit messy.
> 
> Any better ideas?
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> --
> 
> --  
> David Pilato  
> [http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [December 17, 2012, 9:09pm UTC](https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088/6 "2012-12-17T21:09:25Z")

</div>

On 12/17/2012 10:24 AM, Igor Motov wrote:

> I agree with David, type by developer is feasible approach here if you  
> don't have too many developers.

Amy,

For the multiple-type solution keep in mind that you can search on all  
types in an index, so your searches don't even have to decide the type.

Another trick would be to keep one type and then simply wrap the Json  
given in one more level. Then you can use the automatic flattening of  
fields available in searches or work with wildcard fields in your  
search, depending on your application's need.

curl localhost:9200/myindex/mytype/1 -d '_{ "DocAmyVersion55"  
\*\*{_"well": {"hi":"there"}}_}_'  
curl localhost:9200/myindex/mytype/2 -d '_{ "DocPaulVersion1 {_ "well":  
"hey"}_}_'

-Paul

--

---

<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, 2:59am UTC](https://discuss.elastic.co/t/can-you-have-multiple-mappings-for-a-single-json-object-string/10088/7 "2017-07-06T02:59:34Z")

</div>


