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

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

Product remoteClientOperationDocument = new Product();
            if (remoteClientOperation.getRequestId() != null)
            if (remoteClientOperation.getClientId() != null)
            if (remoteClientOperation.getRemoteClientOperationType() != null)
            if (remoteClientOperation.getRequestTime() != null)
            if (remoteClientOperation.getResponseTime() != null)
            if (remoteClientOperation.getResponseText() != null)

then pass this to action

UpdateOperation<Product, Product> updateOperation = new UpdateOperation.Builder<Product, Product>()
                    .action(a -> a.doc(client).docAsUpsert(true))

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

Class Product has primitive type?

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

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.

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