# In Update action using java api client when i set few fields of java object and pass the other fields get updated

**URL:** https://discuss.elastic.co/t/in-update-action-using-java-api-client-when-i-set-few-fields-of-java-object-and-pass-the-other-fields-get-updated/320325
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [December 2, 2022, 6:26am UTC](https://discuss.elastic.co/t/in-update-action-using-java-api-client-when-i-set-few-fields-of-java-object-and-pass-the-other-fields-get-updated/320325 "2022-12-02T06:26:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Raghunandan](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@Raghunandan](https://discuss.elastic.co/u/Raghunandan)
#### Post date: [December 2, 2022, 6:26am UTC](https://discuss.elastic.co/t/in-update-action-using-java-api-client-when-i-set-few-fields-of-java-object-and-pass-the-other-fields-get-updated/320325/1 "2022-12-02T06:26:42Z")

</div>

In Update action using java API client when i set few fields of java object and pass the other fields get updated to null in Elasticsearch, and i am not sure how this happens as while sending the object i only set few fields

```auto
Product remoteClientOperationDocument = new Product();
            remoteClientOperationDocument.setId(remoteClientOperation.getId());
            if (remoteClientOperation.getRequestId() != null)
                remoteClientOperationDocument.setRequestId(remoteClientOperation.getRequestId());
            if (remoteClientOperation.getClientId() != null)
                remoteClientOperationDocument.setClientId(remoteClientOperation.getClientId());
            if (remoteClientOperation.getRemoteClientOperationType() != null)
                remoteClientOperationDocument.setRemoteClientOperationType(remoteClientOperation.getRemoteClientOperationType());
            if (remoteClientOperation.getRequestTime() != null)
                remoteClientOperationDocument.setRequestTime(remoteClientOperation.getRequestTime());
            if (remoteClientOperation.getResponseTime() != null)
                remoteClientOperationDocument.setResponseTime(remoteClientOperation.getResponseTime());
            if (remoteClientOperation.getResponseText() != null)
                remoteClientOperationDocument.setResponseText(remoteClientOperation.getResponseText());

```

then pass this to action

```auto
UpdateOperation<Product, Product> updateOperation = new UpdateOperation.Builder<Product, Product>()
                    .id(client.getId())
                    .index(PRODUCT)
                    .action(a -> a.doc(client).docAsUpsert(true))
                    .build();

```

and then elasticsearchclient.bulk(new BulkOperation.Builder().update(updateOperation).build());

but after this the fields that i did not set get updated with null, so i think issue is when i create new Product(); all fields are initialized with null but then how can i create partial document for elasticsearch using java

---

<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: [December 2, 2022, 8:27am UTC](https://discuss.elastic.co/t/in-update-action-using-java-api-client-when-i-set-few-fields-of-java-object-and-pass-the-other-fields-get-updated/320325/2 "2022-12-02T08:27:13Z")

</div>

Class Product has primitive type?

---

<div class="post-metadata">

### Author: ![Raghunandan](https://avatars.discourse-cdn.com/v4/letter/r/a6a055/32.png) [@Raghunandan](https://discuss.elastic.co/u/Raghunandan)
#### Post date: [December 2, 2022, 9:50am UTC](https://discuss.elastic.co/t/in-update-action-using-java-api-client-when-i-set-few-fields-of-java-object-and-pass-the-other-fields-get-updated/320325/3 "2022-12-02T09:50:28Z")

</div>

yes it has primitive data types, So what we did in old impl was to pass hash map in source of update request and put only those properties which were changing but now in source operation hashmap cannot be put it required either the java object in doc of action or sourcefilter value in source but unable to use hash map in any of those and on passing complete object it sets null to not modified properties

---

<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: [December 2, 2022, 12:31pm UTC](https://discuss.elastic.co/t/in-update-action-using-java-api-client-when-i-set-few-fields-of-java-object-and-pass-the-other-fields-get-updated/320325/4 "2022-12-02T12:31:53Z")

</div>

I understood. I also work with bulk to apply updates. The difference is that I don't have primitive fields.  
My suggestion would be that you replace these primitive types (int -\> Integral) and try to apply the update, I believe that the partial update will work. Maybe some Elastic Eng can tell you what to do to improve practice in these cases.

---

<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: [December 30, 2022, 12:32pm UTC](https://discuss.elastic.co/t/in-update-action-using-java-api-client-when-i-set-few-fields-of-java-object-and-pass-the-other-fields-get-updated/320325/5 "2022-12-30T12:32:08Z")

</div>

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