# How to update a single field using the Java API Client?

**URL:** <https://discuss.elastic.co/t/how-to-update-a-single-field-using-the-java-api-client/306679>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [June 8, 2022, 10:20am UTC](https://discuss.elastic.co/t/how-to-update-a-single-field-using-the-java-api-client/306679 "2022-06-08T10:20:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dsc/32/100102_2.png) [@dsc](https://discuss.elastic.co/u/dsc)\
**Post date:** [June 8, 2022, 10:20am UTC](https://discuss.elastic.co/t/how-to-update-a-single-field-using-the-java-api-client/306679/1 "2022-06-08T10:20:28Z")

</div>

I'm currently using the deprecated Java High Level REST Client to partially update a document using something similar to the guide: [Update API | Java REST Client [7.17] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-update.html)

I'm trying to migrate to the latest Elasticsearch and switch over to using the non-deprecated Java API Client instead, but partial updates are not covered in: [Using the Java API Client | Elasticsearch Java API Client [8.2] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/usage.html)

There's an [UpdateRequest (java-client 8.2.2 API)](https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.2.2/co/elastic/clients/elasticsearch/core/UpdateRequest.html) class, but this appears to be parameterised by 2 types, `TDocument` and `TPartialDocument`, but it's not clear what needs to be implemented to just update a single field here.

Are there any simple examples available on how to do this? I'm not sure how new the Java API Client is, it might just be that the documentation hasn't caught up yet, and it's not recommended for general use yet.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [June 8, 2022, 12:33pm UTC](https://discuss.elastic.co/t/how-to-update-a-single-field-using-the-java-api-client/306679/2 "2022-06-08T12:33:34Z")

</div>

Hi!

This example update partial document:

```auto
    Foo foo = Foo.builder()
        .year(2023)
        .build();
    return client.update(u -> u.index("your_index")
        .id("id-foo")
        .doc(foo), Foo.class);

```

---

<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, 2022, 12:34pm UTC](https://discuss.elastic.co/t/how-to-update-a-single-field-using-the-java-api-client/306679/3 "2022-07-06T12:34:11Z")

</div>

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