# Error in indexing document in elasticsearch

**URL:** <https://discuss.elastic.co/t/error-in-indexing-document-in-elasticsearch/10144>\
**Category:** Elasticsearch\
**Created:** [December 21, 2012, 6:03am UTC](https://discuss.elastic.co/t/error-in-indexing-document-in-elasticsearch/10144 "2012-12-21T06:03:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rahulg](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rahulg](https://discuss.elastic.co/u/rahulg)\
**Post date:** [December 21, 2012, 6:03am UTC](https://discuss.elastic.co/t/error-in-indexing-document-in-elasticsearch/10144/1 "2012-12-21T06:03:18Z")

</div>

When I try to index this document, I am getting an exception. stack trace is given below.

curl -XPOST localhost:9200/index1/talk?pretty=1 -d '

{

```
"_id" : ObjectId("503b29efe4b032e338f0581b"),

"_oid" : NumberLong(1182053),

"ns" : [

    {

        "n" : "Soldeu",

        "l" : "en",

        "t" : "p"

    }

]

```

}'

STACKTRACE :

org.elasticsearch.index.mapper.MapperParsingException: Failed to parse  
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:509)  
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:438)  
at org.elasticsearch.index.shard.service.InternalIndexShard.prepareCreate(InternalIndexShard.java:287)  
at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnPrimary(TransportIndexAction.java:210)  
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:532)  
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:430)  
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:662)  
Caused by: org.elasticsearch.common.jackson.core.JsonParseException: Unexpected character ('O' (code 79)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')  
at [Source: [B@5e7d093a; line: 4, column: 10]  
at org.elasticsearch.common.jackson.core.JsonParser.\_constructError(JsonParser.java:1284)  
at org.elasticsearch.common.jackson.core.base.ParserMinimalBase.\_reportError(ParserMinimalBase.java:588)  
at org.elasticsearch.common.jackson.core.base.ParserMinimalBase.\_reportUnexpectedChar(ParserMinimalBase.java:509)  
at org.elasticsearch.common.jackson.core.json.UTF8StreamJsonParser.\_handleUnexpectedValue(UTF8StreamJsonParser.java:2094)  
at org.elasticsearch.common.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:561)  
at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:48)  
at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:461)  
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:494)  
... 8 more

MAPPING:

curl -XPUT localhost:9200/index1?pretty=1 -d '{

```
    "mappings" : {

        "type1" : {

            "_all" : {"enabled" : false},

            "properties" : {

 "ns" : {

        "dynamic" : "true",

    		"properties" : {

	          "n" : {

	            "type" : "string"

	          },

	          "l" : {

	            "type" : "string"

	          },

		"t" : {

	            "type" : "string"

	          }

    }

  }

            }

        }

    }

```

}'

The problem seems to be in providing the mapping for ObjectId and NumberLong  
ObjectId = org.bson.types.ObjectId and NumberLong = java.lang.Double

Can someone please help me in how to handle such fields with non-primitive datatypes

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [December 21, 2012, 6:41am UTC](https://discuss.elastic.co/t/error-in-indexing-document-in-elasticsearch/10144/2 "2012-12-21T06:41:04Z")

</div>

ObjectId and NumberLong are MongoDB concepts (IIRC). Simply map your  
ObjectId as a string and NumberLong as a long.

--  
Ivan

On Thu, Dec 20, 2012 at 10:03 PM, [rahulg@travenues.com](mailto:rahulg@travenues.com) wrote:

> ObjectId

--

---

<div class="post-metadata">

**Author:** ![rahulg](https://avatars.discourse-cdn.com/v4/letter/r/7ab992/32.png) [@rahulg](https://discuss.elastic.co/u/rahulg)\
**Post date:** [December 21, 2012, 6:58am UTC](https://discuss.elastic.co/t/error-in-indexing-document-in-elasticsearch/10144/3 "2012-12-21T06:58:39Z")

</div>

Do I need to change these fields in MongoDB itself or just changing the ES  
mapping should work.

I have tried changing my mapping to  
curl -XPUT localhost:9200/index1?pretty=1 -d '{  
"mappings": {  
"type1": {  
"\_all": {  
"enabled": false  
},  
"properties": {  
"\_id": {  
"type": "string"  
},  
"\_oid": {  
"type": "long"  
},  
"ns": {  
"dynamic": "true",  
"properties": {  
"n": {  
"type": "string"  
},  
"l": {  
"type": "string"  
},  
"t": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}'

but of no avail. I am still getting the same error for inserting the above  
mentioned document.  
On Friday, December 21, 2012 12:11:04 PM UTC+5:30, Ivan Brusic wrote:

> ObjectId and NumberLong are MongoDB concepts (IIRC). Simply map your  
> ObjectId as a string and NumberLong as a long.
> 
> --  
> Ivan
> 
> On Thu, Dec 20, 2012 at 10:03 PM, \<[rah...@travenues.com](mailto:rah...@travenues.com) \<javascript:\>\>wrote:
> 
> > ObjectId

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [December 21, 2012, 5:25pm UTC](https://discuss.elastic.co/t/error-in-indexing-document-in-elasticsearch/10144/4 "2012-12-21T17:25:10Z")

</div>

The issue is not the mapping, but the document itself. Like I stated  
before, ObjectId and NumberLong are MongoDB concepts. Those tags are not  
standard JSON. The JSON parser will only accept standard JSON documents.  
Not sure how you are integrating MongoDB with Elasticsearch. ObjectIds in  
MongoDB contained specific information which is useless in Elasticsearch  
(machine identifier, counter), so a pure String field would be a suitable  
replacement. In fact, ids in ES should be strings.

NumberLong can just be a standard number field. I don't use JSON, but I  
don't think JSON has number types. Anyone care to elaborate?

Cheers,

Ivan

On Thu, Dec 20, 2012 at 10:58 PM, [rahulg@travenues.com](mailto:rahulg@travenues.com) wrote:

> change these fields in MongoDB itself or just changing

--

---

<div class="post-metadata">

**Author:** ![Aditya\_Arisetty](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aditya_arisetty/32/2222_2.png) [@Aditya\_Arisetty](https://discuss.elastic.co/u/Aditya_Arisetty)\
**Post date:** [June 7, 2013, 9:07am UTC](https://discuss.elastic.co/t/error-in-indexing-document-in-elasticsearch/10144/5 "2013-06-07T09:07:52Z")

</div>

Hi Rahul,

I am trying to index the documents in MognoDB using the mongo river. Were  
you able to find any solution for this problem. Any help would be  
appreciated.

Thanks,  
Aditya

On Friday, December 21, 2012 6:58:39 AM UTC, Rahul Gupta wrote:

> Do I need to change these fields in MongoDB itself or just changing the ES  
> mapping should work.
> 
> I have tried changing my mapping to  
> curl -XPUT localhost:9200/index1?pretty=1 -d '{  
> "mappings": {  
> "type1": {  
> "\_all": {  
> "enabled": false  
> },  
> "properties": {  
> "\_id": {  
> "type": "string"  
> },  
> "\_oid": {  
> "type": "long"  
> },  
> "ns": {  
> "dynamic": "true",  
> "properties": {  
> "n": {  
> "type": "string"  
> },  
> "l": {  
> "type": "string"  
> },  
> "t": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }  
> }  
> }'
> 
> but of no avail. I am still getting the same error for inserting the above  
> mentioned document.  
> On Friday, December 21, 2012 12:11:04 PM UTC+5:30, Ivan Brusic wrote:
> 
> > ObjectId and NumberLong are MongoDB concepts (IIRC). Simply map your  
> > ObjectId as a string and NumberLong as a long.
> > 
> > --  
> > Ivan
> > 
> > On Thu, Dec 20, 2012 at 10:03 PM, [rah...@travenues.com](mailto:rah...@travenues.com) wrote:
> > 
> > > ObjectId

--  
Brand View\* \*- Analyse the retail market, instantly

UK: 0844 357 9970  
USA: 1-800-968-1876

Latest from the blog: New Out of Stock feature now available -

> **[Acuity Pricing | Competitor Price Monitoring | Price Tracking](https://www.acuitypricing.com/)**
>
> Acuity Pricing provides real-time competitor price monitoring data. Track product price changes and activity to form competitive, profitable strategies.

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:32am UTC](https://discuss.elastic.co/t/error-in-indexing-document-in-elasticsearch/10144/6 "2017-07-06T02:32:23Z")

</div>


