# Getting MapperParsingException while parsing a string and a number?

**URL:** <https://discuss.elastic.co/t/getting-mapperparsingexception-while-parsing-a-string-and-a-number/7279>\
**Category:** Elasticsearch\
**Created:** [April 9, 2012, 8:52pm UTC](https://discuss.elastic.co/t/getting-mapperparsingexception-while-parsing-a-string-and-a-number/7279 "2012-04-09T20:52:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean\_Sebastien\_Delfi](https://avatars.discourse-cdn.com/v4/letter/j/f07891/32.png) [@Jean\_Sebastien\_Delfi](https://discuss.elastic.co/u/Jean_Sebastien_Delfi)\
**Post date:** [April 9, 2012, 8:52pm UTC](https://discuss.elastic.co/t/getting-mapperparsingexception-while-parsing-a-string-and-a-number/7279/1 "2012-04-09T20:52:31Z")

</div>

Hi,

I'm trying to put JSON data into Elastic Search like this:  
curl -XPUT '[http://localhost:9200/test/tweet/1](http://localhost:9200/test/tweet/1)' -d '{ "user": "jane doe",  
"contentType": "article", "content": { "title": "some news", "text": "blah  
blah" } }'  
curl -XPUT '[http://localhost:9200/test/tweet/2](http://localhost:9200/test/tweet/2)' -d '{ "user": "john doe",  
"contentType": "url", "content": "[http://example.com/foo](http://example.com/foo)" }'  
curl -XPUT '[http://localhost:9200/test/tweet/3](http://localhost:9200/test/tweet/3)' -d '{ "user": "john doe",  
"contentType": "number", "content": 123 }'

This is very similar to the example on the Elastic Search home page, except  
that my message content can be of different types (a structured doc, a url,  
or even just a number).

The first PUT works, but then I'm getting errors like this:  
{"ok":true,"\_index":"test","\_type":"tweet","\_id":"1","\_version":2}  
{"error":"MapperParsingException[object mapping for [tweet] tried to parse  
as object, but got EOF, has a concrete value been provided to  
it?]","status":400}  
{"error":"MapperParsingException[object mapping for [tweet] tried to parse  
as object, but got EOF, has a concrete value been provided to  
it?]","status":400}

Any idea of what's going wrong here? Why is Elastic Search trying to parse  
"[http://example.com/foo](http://example.com/foo)" and 123 as objects?

Thanks!

- Jean-Sebastien

---

<div class="post-metadata">

**Author:** ![atlaste](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atlaste/32/2928_2.png) [@atlaste](https://discuss.elastic.co/u/atlaste)\
**Post date:** [April 10, 2012, 6:28am UTC](https://discuss.elastic.co/t/getting-mapperparsingexception-while-parsing-a-string-and-a-number/7279/2 "2012-04-10T06:28:26Z")

</div>

The reason is because the first line tells ES to do so: you put a title and a text in there. From that point forward, the type of the content field in ES is 'set' to a type (e.g. type = 'object').

From search perspective this makes perfect sense.

The way to solve this is **not** to 'overload' content with different types, but make them different fields:

curl -XPUT '[http://localhost:9200/test/tweet/1](http://localhost:9200/test/tweet/1)' -d '{ "user": "jane doe", "contentType": "article", "content1": { "title": "some news", "text": "blah blah" } }'  
curl -XPUT '[http://localhost:9200/test/tweet/2](http://localhost:9200/test/tweet/2)' -d '{ "user": "john doe", "contentType": "url", "content2": "[http://example.com/foo](http://example.com/foo)" }'  
curl -XPUT '[http://localhost:9200/test/tweet/3](http://localhost:9200/test/tweet/3)' -d '{ "user": "john doe", "contentType": "number", "content3": 123 }'

I assume at this point you are going to be concerned with memory usage for storing all the null's, judging by your example. Don't; ES data structures don't store null's.

Kind regards,  
Stefan.

---

<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:** [April 10, 2012, 10:29pm UTC](https://discuss.elastic.co/t/getting-mapperparsingexception-while-parsing-a-string-and-a-number/7279/3 "2012-04-10T22:29:35Z")

</div>

By default, elasticsearch tries to deduce field types from filed values. If  
you will check mappings after the first PUT request, you will see something  
like this:

$ curl '[http://localhost:9200/test/\_mapping?pretty=true](http://localhost:9200/test/_mapping?pretty=true)'  
{  
"test" : {  
"tweet" : {  
"properties" : {  
\* "content" : {\*

- 

```
     "dynamic" : "true",*

```

- 

```
     "properties" : {*

```

- 

```
       "text" : { "type" : "string"},*

```

- 

```
       "title" : { "type" : "string"}*

```

- 

```
     }*
  },
  "contentType" : {"type" : "string"},
  "user" : {"type" : "string"}
}

```

}  
}  
}

As you can see from this mapping, elasticsearch is now treating content as  
an object type field  
([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html)) and  
it will be expecting to see objects in this field until index is deleted.  
If you ran the second requests first, it would have expected to see strings  
there and failed on object.

There are a couple of ways around it. You can use different field names for  
different types:

curl -XPUT '[http://localhost:9200/test/tweet/1](http://localhost:9200/test/tweet/1)' -d '{ "user": "jane doe",  
"contentType": "article", "content\*\_article\*": { "title": "some news",  
"text": "blah blah" } }'  
curl -XPUT '[http://localhost:9200/test/tweet/2](http://localhost:9200/test/tweet/2)' -d '{ "user": "john doe",  
"contentType": "url", "content\*\_url\*": "[http://example.com/foo](http://example.com/foo)" }'  
curl -XPUT '[http://localhost:9200/test/tweet/3](http://localhost:9200/test/tweet/3)' -d '{ "user": "john doe",  
"contentType": "number", "content\*\_number\*": 123 }'

Or you can assign different elasticsearch types to records with different  
content types, (different elasticsearch types can have different mappings).

curl -XPUT '[http://localhost:9200/test/\*article\*/1](http://localhost:9200/test/*article*/1)' -d '{ "user": "jane  
doe", "contentType": "article", "content": { "title": "some news", "text":  
"blah blah" } }'  
curl -XPUT '[http://localhost:9200/test/\*url\*/2](http://localhost:9200/test/*url*/2)' -d '{ "user": "john doe",  
"contentType": "url", "content": "[http://example.com/foo](http://example.com/foo)" }'  
curl -XPUT '[http://localhost:9200/test/\*number\*/3](http://localhost:9200/test/*number*/3)' -d '{ "user": "john  
doe", "contentType": "number", "content": 123 }'

On Monday, April 9, 2012 4:52:31 PM UTC-4, Jean-Sebastien Delfino wrote:

> Hi,
> 
> I'm trying to put JSON data into Elastic Search like this:  
> curl -XPUT '[http://localhost:9200/test/tweet/1](http://localhost:9200/test/tweet/1)' -d '{ "user": "jane doe",  
> "contentType": "article", "content": { "title": "some news", "text": "blah  
> blah" } }'  
> curl -XPUT '[http://localhost:9200/test/tweet/2](http://localhost:9200/test/tweet/2)' -d '{ "user": "john doe",  
> "contentType": "url", "content": "[http://example.com/foo](http://example.com/foo)" }'  
> curl -XPUT '[http://localhost:9200/test/tweet/3](http://localhost:9200/test/tweet/3)' -d '{ "user": "john doe",  
> "contentType": "number", "content": 123 }'
> 
> This is very similar to the example on the Elastic Search home page,  
> except that my message content can be of different types (a structured doc,  
> a url, or even just a number).
> 
> The first PUT works, but then I'm getting errors like this:  
> {"ok":true,"\_index":"test","\_type":"tweet","\_id":"1","\_version":2}  
> {"error":"MapperParsingException[object mapping for [tweet] tried to parse  
> as object, but got EOF, has a concrete value been provided to  
> it?]","status":400}  
> {"error":"MapperParsingException[object mapping for [tweet] tried to parse  
> as object, but got EOF, has a concrete value been provided to  
> it?]","status":400}
> 
> Any idea of what's going wrong here? Why is Elastic Search trying to parse  
> "[http://example.com/foo](http://example.com/foo)" and 123 as objects?
> 
> Thanks!
> 
> - Jean-Sebastien

---

<div class="post-metadata">

**Author:** ![Subbarao\_Kondragunta](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Subbarao\_Kondragunta](https://discuss.elastic.co/u/Subbarao_Kondragunta)\
**Post date:** [December 10, 2014, 4:55pm UTC](https://discuss.elastic.co/t/getting-mapperparsingexception-while-parsing-a-string-and-a-number/7279/4 "2014-12-10T16:55:05Z")

</div>

how can we achieve the same thing using java api?

On Tuesday, April 10, 2012 5:29:35 PM UTC-5, Igor Motov wrote:

> By default, elasticsearch tries to deduce field types from filed values.  
> If you will check mappings after the first PUT request, you will see  
> something like this:
> 
> $ curl '[http://localhost:9200/test/\_mapping?pretty=true](http://localhost:9200/test/_mapping?pretty=true)'  
> {  
> "test" : {  
> "tweet" : {  
> "properties" : {  
> \* "content" : {\*
> 
> - 
> 
> ```
> "dynamic" : "true",*
> 
> ```
> 
> - 
> 
> ```
> "properties" : {*
> 
> ```
> 
> - 
> 
> ```
> "text" : { "type" : "string"},*
> 
> ```
> 
> - 
> 
> ```
> "title" : { "type" : "string"}*
> 
> ```
> 
> - 
> 
> ```
> }*
> },
> "contentType" : {"type" : "string"},
> "user" : {"type" : "string"}
> }
> 
> ```
> 
> }  
> }  
> }
> 
> As you can see from this mapping, elasticsearch is now treating content as  
> an object type field (  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/object-type.html))  
> and it will be expecting to see objects in this field until index is  
> deleted. If you ran the second requests first, it would have expected to  
> see strings there and failed on object.
> 
> There are a couple of ways around it. You can use different field names  
> for different types:
> 
> curl -XPUT '[http://localhost:9200/test/tweet/1](http://localhost:9200/test/tweet/1)' -d '{ "user": "jane doe",  
> "contentType": "article", "content\*\_article\*": { "title": "some news",  
> "text": "blah blah" } }'  
> curl -XPUT '[http://localhost:9200/test/tweet/2](http://localhost:9200/test/tweet/2)' -d '{ "user": "john doe",  
> "contentType": "url", "content\*\_url\*": "[http://example.com/foo](http://example.com/foo)" }'  
> curl -XPUT '[http://localhost:9200/test/tweet/3](http://localhost:9200/test/tweet/3)' -d '{ "user": "john doe",  
> "contentType": "number", "content\*\_number\*": 123 }'
> 
> Or you can assign different elasticsearch types to records with different  
> content types, (different elasticsearch types can have different mappings).
> 
> curl -XPUT '[http://localhost:9200/test/\*article\*/1](http://localhost:9200/test/*article*/1)' -d '{ "user": "jane  
> doe", "contentType": "article", "content": { "title": "some news", "text":  
> "blah blah" } }'  
> curl -XPUT '[http://localhost:9200/test/\*url\*/2](http://localhost:9200/test/*url*/2)' -d '{ "user": "john doe",  
> "contentType": "url", "content": "[http://example.com/foo](http://example.com/foo)" }'  
> curl -XPUT '[http://localhost:9200/test/\*number\*/3](http://localhost:9200/test/*number*/3)' -d '{ "user": "john  
> doe", "contentType": "number", "content": 123 }'
> 
> On Monday, April 9, 2012 4:52:31 PM UTC-4, Jean-Sebastien Delfino wrote:
> 
> > Hi,
> > 
> > I'm trying to put JSON data into Elastic Search like this:  
> > curl -XPUT '[http://localhost:9200/test/tweet/1](http://localhost:9200/test/tweet/1)' -d '{ "user": "jane  
> > doe", "contentType": "article", "content": { "title": "some news", "text":  
> > "blah blah" } }'  
> > curl -XPUT '[http://localhost:9200/test/tweet/2](http://localhost:9200/test/tweet/2)' -d '{ "user": "john  
> > doe", "contentType": "url", "content": "[http://example.com/foo](http://example.com/foo)" }'  
> > curl -XPUT '[http://localhost:9200/test/tweet/3](http://localhost:9200/test/tweet/3)' -d '{ "user": "john  
> > doe", "contentType": "number", "content": 123 }'
> > 
> > This is very similar to the example on the Elastic Search home page,  
> > except that my message content can be of different types (a structured doc,  
> > a url, or even just a number).
> > 
> > The first PUT works, but then I'm getting errors like this:  
> > {"ok":true,"\_index":"test","\_type":"tweet","\_id":"1","\_version":2}  
> > {"error":"MapperParsingException[object mapping for [tweet] tried to  
> > parse as object, but got EOF, has a concrete value been provided to  
> > it?]","status":400}  
> > {"error":"MapperParsingException[object mapping for [tweet] tried to  
> > parse as object, but got EOF, has a concrete value been provided to  
> > it?]","status":400}
> > 
> > Any idea of what's going wrong here? Why is Elastic Search trying to  
> > parse "[http://example.com/foo](http://example.com/foo)" and 123 as objects?
> > 
> > Thanks!
> > 
> > - Jean-Sebastien

--  
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/d844642c-2bfe-4c78-b559-67da03236aad%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d844642c-2bfe-4c78-b559-67da03236aad%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, 12:44am UTC](https://discuss.elastic.co/t/getting-mapperparsingexception-while-parsing-a-string-and-a-number/7279/5 "2017-07-06T00:44:24Z")

</div>


