Java Update API and Nested field : MapperParsingException: object mapping for [xxx] tried to parse field [xxx] as object, but found a concrete value

Hello,

I'm using elasticsearch 5.2.2.
I have a document with a nested field called "policies".
Sample data:

{ 
     "id": 1,
     "policies": [
            {
                "name": "A",
                "dates": [
                    "02/01/2013"
                ],
                "status": [
                    "CLOSED"
                ],
                "policieId": 1
            },
            {
                "name": "B",
                "dates": [
                    "04/04/2013"
                ],
                "status": [
                    "RUNNING"
                ],
                "policieId": 19
            }
        ]
}

When I want to update the "policies" nested field using the standard REST API, I use:

POST records/record/1/_update
{
  "doc": {
    "policies": [
      {
        "name": "c",
        "dates": [ "06/03/2018" ],
        "status": [ "DRAFT" ],
        "policieId": 6
      }
    ]
  }
}

And it works, it replaces my previous collection with the new one.
When I want to do the same using java API, ElasticSearch returns me this error:

my code:

UpdateResponse updateResponse = client.prepareUpdate("records", "record", "1")
                .setDoc("policies", value)
                .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
                .get();

the "value" variable contains the JSON string :

[ {
  "name": "c",
  "dates": [ "06/03/2018" ],
  "status": [ "DRAFT" ],
  "policieId": 6
} ]

the error :

org.elasticsearch.index.mapper.MapperParsingException: object mapping for [policies] tried to parse field [policies] as object, but found a concrete value
	at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:349)
	at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrField(DocumentParser.java:446)
	at org.elasticsearch.index.mapper.DocumentParser.parseValue(DocumentParser.java:575)
	at org.elasticsearch.index.mapper.DocumentParser.innerParseObject(DocumentParser.java:395)
	at org.elasticsearch.index.mapper.DocumentParser.parseObjectOrNested(DocumentParser.java:372)
	at org.elasticsearch.index.mapper.DocumentParser.internalParseDocument(DocumentParser.java:93)
	at org.elasticsearch.index.mapper.DocumentParser.parseDocument(DocumentParser.java:66)
	at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:275)
	at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java:533)
	at org.elasticsearch.index.shard.IndexShard.prepareIndexOnPrimary(IndexShard.java:510)
	at org.elasticsearch.action.index.TransportIndexAction.prepareIndexOperationOnPrimary(TransportIndexAction.java:196)
	at org.elasticsearch.action.index.TransportIndexAction.executeIndexRequestOnPrimary(TransportIndexAction.java:201)
	at org.elasticsearch.action.index.TransportIndexAction.onPrimaryShard(TransportIndexAction.java:166)
	at org.elasticsearch.action.index.TransportIndexAction.onPrimaryShard(TransportIndexAction.java:68)
	at org.elasticsearch.action.support.replication.TransportWriteAction.shardOperationOnPrimary(TransportWriteAction.java:76)
	at org.elasticsearch.action.support.replication.TransportWriteAction.shardOperationOnPrimary(TransportWriteAction.java:49)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryShardReference.perform(TransportReplicationAction.java:914)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryShardReference.perform(TransportReplicationAction.java:884)
	at org.elasticsearch.action.support.replication.ReplicationOperation.execute(ReplicationOperation.java:113)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.onResponse(TransportReplicationAction.java:327)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.onResponse(TransportReplicationAction.java:262)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$1.onResponse(TransportReplicationAction.java:864)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$1.onResponse(TransportReplicationAction.java:861)
	at org.elasticsearch.index.shard.IndexShardOperationsLock.acquire(IndexShardOperationsLock.java:147)
	at org.elasticsearch.index.shard.IndexShard.acquirePrimaryOperationLock(IndexShard.java:1652)
	at org.elasticsearch.action.support.replication.TransportReplicationAction.acquirePrimaryShardReference(TransportReplicationAction.java:873)
	at org.elasticsearch.action.support.replication.TransportReplicationAction.access$400(TransportReplicationAction.java:92)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$AsyncPrimaryAction.doRun(TransportReplicationAction.java:279)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:258)
	at org.elasticsearch.action.support.replication.TransportReplicationAction$PrimaryOperationTransportHandler.messageReceived(TransportReplicationAction.java:250)
	at org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:69)
	at org.elasticsearch.transport.TransportService$7.doRun(TransportService.java:610)
	at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:596)
	at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

I found a workaround using update by hashmap, as stated here (2nd sample):

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.