Update Java

How to write following request from java
POST index/type/1/_update
{
"doc" : {
"subcat" : [
{
"name": "Test",
"id": [
{
"value": "IP/IP1",
"type": "key"
},
{
"value": "0000151",
"type": "value"
}
],
"role": [
"role"
]
},
{
"name": "Test",
"identifier": [
{
"value": "11/MNP",
"type": "key"
},
{
"value": "0677427",
"type": "value"
}
]
}
]
}
}

This does not work:
UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index(index);
updateRequest.type(type);
updateRequest.id("1");
updateRequest.doc(jsonBuilder().startObject()
.field("subcat", object)
.endObject());
Client.update(updateRequest).actionGet();

Error:
MapperParsingException[object mapping for [subcat] tried to parse field [null] as object, but found a concrete value]

  1. Please format code snippets with ```, they are much easier to read that way.
  2. It looks like you are using the transport client - it has actionGet. We're moving away from that, slowly but surely. We haven't actually deprecated it, but it is deprecated in our hearts. Stick with the high level rest client.
  3. What is object in your code? If it is a map or a list we'll try and unroll it. It looks like the error message is caused by you doing something like
POST /index/type/1/_update
{
  "doc": {
    "subcat": null
  }
}

Or maybe "subcat": [null]. We're a little tricky about lists so I can't tell from the exception message.

Object in code is a list and size of the list is 2.

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