# Update Java

**URL:** <https://discuss.elastic.co/t/update-java/152989>\
**Category:** Elasticsearch\
**Created:** [October 18, 2018, 11:45am UTC](https://discuss.elastic.co/t/update-java/152989 "2018-10-18T11:45:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vnitdeepak](https://avatars.discourse-cdn.com/v4/letter/v/9fc29f/32.png) [@vnitdeepak](https://discuss.elastic.co/u/vnitdeepak)\
**Post date:** [October 18, 2018, 11:45am UTC](https://discuss.elastic.co/t/update-java/152989/1 "2018-10-18T11:45:29Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 18, 2018, 12:37pm UTC](https://discuss.elastic.co/t/update-java/152989/2 "2018-10-18T12:37:17Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![vnitdeepak](https://avatars.discourse-cdn.com/v4/letter/v/9fc29f/32.png) [@vnitdeepak](https://discuss.elastic.co/u/vnitdeepak)\
**Post date:** [October 18, 2018, 5:14pm UTC](https://discuss.elastic.co/t/update-java/152989/3 "2018-10-18T17:14:20Z")

</div>

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

---

<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:** [November 15, 2018, 5:14pm UTC](https://discuss.elastic.co/t/update-java/152989/4 "2018-11-15T17:14:21Z")

</div>

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