Getting MapperParsingException while parsing a string and a number?

Hi,

I'm trying to put JSON data into Elastic Search like this:
curl -XPUT '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' -d '{ "user": "john doe",
"contentType": "url", "content": "http://example.com/foo" }'
curl -XPUT '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" and 123 as objects?

Thanks!

  • Jean-Sebastien

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' -d '{ "user": "jane doe", "contentType": "article", "content1": { "title": "some news", "text": "blah blah" } }'
curl -XPUT 'http://localhost:9200/test/tweet/2' -d '{ "user": "john doe", "contentType": "url", "content2": "http://example.com/foo" }'
curl -XPUT '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.

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'
{
"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) 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' -d '{ "user": "jane doe",
"contentType": "article", "content*_article*": { "title": "some news",
"text": "blah blah" } }'
curl -XPUT 'http://localhost:9200/test/tweet/2' -d '{ "user": "john doe",
"contentType": "url", "content*_url*": "http://example.com/foo" }'
curl -XPUT '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' -d '{ "user": "jane
doe", "contentType": "article", "content": { "title": "some news", "text":
"blah blah" } }'
curl -XPUT 'http://localhost:9200/test/*url*/2' -d '{ "user": "john doe",
"contentType": "url", "content": "http://example.com/foo" }'
curl -XPUT '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' -d '{ "user": "jane doe",
"contentType": "article", "content": { "title": "some news", "text": "blah
blah" } }'
curl -XPUT 'http://localhost:9200/test/tweet/2' -d '{ "user": "john doe",
"contentType": "url", "content": "http://example.com/foo" }'
curl -XPUT '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" and 123 as objects?

Thanks!

  • Jean-Sebastien

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'
{
"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)
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' -d '{ "user": "jane doe",
"contentType": "article", "content*_article*": { "title": "some news",
"text": "blah blah" } }'
curl -XPUT 'http://localhost:9200/test/tweet/2' -d '{ "user": "john doe",
"contentType": "url", "content*_url*": "http://example.com/foo" }'
curl -XPUT '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' -d '{ "user": "jane
doe", "contentType": "article", "content": { "title": "some news", "text":
"blah blah" } }'
curl -XPUT 'http://localhost:9200/test/*url*/2' -d '{ "user": "john doe",
"contentType": "url", "content": "http://example.com/foo" }'
curl -XPUT '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' -d '{ "user": "jane
doe", "contentType": "article", "content": { "title": "some news", "text":
"blah blah" } }'
curl -XPUT 'http://localhost:9200/test/tweet/2' -d '{ "user": "john
doe", "contentType": "url", "content": "http://example.com/foo" }'
curl -XPUT '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" 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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/d844642c-2bfe-4c78-b559-67da03236aad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.