# Elasticsearch Java API update document GetResult is always null

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-api-update-document-getresult-is-always-null/54272>\
**Category:** Elasticsearch\
**Created:** [June 29, 2016, 12:01pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-document-getresult-is-always-null/54272 "2016-06-29T12:01:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![VenkateshK](https://avatars.discourse-cdn.com/v4/letter/v/90ced4/32.png) [@VenkateshK](https://discuss.elastic.co/u/VenkateshK)\
**Post date:** [June 29, 2016, 12:01pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-document-getresult-is-always-null/54272/1 "2016-06-29T12:01:59Z")

</div>

I am trying to update a document through Java Update API.

I am using `UpdateRequest` to send a request for update.

```
UpdateRequest updateRequest = new UpdateRequest(index, type, id).script(
            new Script("ctx._source.'Test Status' = newtestStatus", ScriptType.INLINE, null, updateRequestParams));
updateResponse = client.update(updateRequest).get();
GetResult getResult = updateResponse.getGetResult();
if (getResult.isExists() & getResult.getVersion() == updateResponse.getVersion()) {
    testStatusUpdated = true;
}

```

Here, I always get `java.lang.NullPointerException` at `getResult.isExists()` and this because `GetResult getResult = updateResponse.getGetResult();` is `null`.

When I checked the result manually, it is getting updated as required. `"Test Status": "STOPPED"` in the document.

`getResult` is always returned `null` due to which I am not able to check programmatically if the document is updated.

Also, is there any other way to check if document is updated?

---

<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:** [June 29, 2016, 12:27pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-document-getresult-is-always-null/54272/2 "2016-06-29T12:27:47Z")

</div>

> [@VenkateshK](#):
>
> When I checked the result manually, it is getting updated as required. "Test Status": "STOPPED" in the document.

It should throw an exception if it isn't updated. It looks like `getGetResult` only has a thing in it is `fields` has fields in it or if you delete the document.

---

<div class="post-metadata">

**Author:** ![VenkateshK](https://avatars.discourse-cdn.com/v4/letter/v/90ced4/32.png) [@VenkateshK](https://discuss.elastic.co/u/VenkateshK)\
**Post date:** [June 29, 2016, 1:07pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-document-getresult-is-always-null/54272/3 "2016-06-29T13:07:03Z")

</div>

`GetResult getResult = updateResponse.getGetResult()` is always `null` and because of this, i cannot use any of it's methods like `getResult.getFields()`

---

<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:** [June 29, 2016, 1:20pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-document-getresult-is-always-null/54272/4 "2016-06-29T13:20:29Z")

</div>

`updateRequest.fields("cat")` should make GetResult come back. The thing you are doing to check the result isn't needed though `.get` will throw an exception if Elasticsearch failed to perform the update.

---

<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 5, 2017, 10:39pm UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-document-getresult-is-always-null/54272/5 "2017-07-05T22:39:32Z")

</div>


