# Why is .doc() missing in UpdateOperation?

**URL:** <https://discuss.elastic.co/t/why-is-doc-missing-in-updateoperation/317587>\
**Category:** Elasticsearch\
**Created:** [October 27, 2022, 6:35am UTC](https://discuss.elastic.co/t/why-is-doc-missing-in-updateoperation/317587 "2022-10-27T06:35:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Gattinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_gattinger/32/99690_2.png) [@Michael\_Gattinger](https://discuss.elastic.co/u/Michael_Gattinger)\
**Post date:** [October 27, 2022, 6:35am UTC](https://discuss.elastic.co/t/why-is-doc-missing-in-updateoperation/317587/1 "2022-10-27T06:35:32Z")

</div>

Hi, as an junior Java developer try to understand the things by using the "easy way".

I actually don't understand what requirements like this mean and can't write code from the scratch with that information:

```auto
update(Function<Builder<TDocument,TPartialDocument>, ObjectBuilder<UpdateOperation<TDocument,TPartialDocument>>> fn) : ObjectBuilder<BulkOperation> - Builder

```

I actually need to first program the elaborated way to see what is happening in the background.

So for example when i have something like this:

```auto
client.delete(dere -> dere.index("foo").id(delete_candidate));

```

I could put it in a BulkRequest by doing as follows:

```auto
BulkRequest.Builder brb = new BulkRequest.Builder();
DeleteOperation deop2 = new DeleteOperation.Builder().index("foo").id(delete_candidate).build();
BulkOperation bo = new BulkOperation.Builder().delete(deop2).build();
brb.operations(bo);

```

or i can actually shorten this up by writing:

```auto
brb.operations(buop -> buop.delete(deop -> deop.index("foo").id(delete_candidate)));

```

"Lesson learned": Just copy the lampda-expression into the _delete_-part of the brb.operations.

Same for indexing:

```auto
Rechnung r5 = new Rechnung(13293, Calendar.getInstance().getTime(), 79.99f, Gläubiger, Schuldner);
client.index(inre -> inre.index("foo").document(r5));

BulkOperation bo2 = new BulkOperation.Builder().index(i -> i.index("foo").document(r5)).build();
brb.operations(bo2);

brb.operations(buop -> buop.index(inop -> inop.index("foo").document(r5)));

```

"Lesson learned": Just copy the lampda-expression into the _index_-part of the brb.operations.

But if i do so for updating:

```auto
client.update(upre -> upre.index("foo").id("bar").doc(r5), Rechnung.class);

```

"Do what i have learned": copy the lampda-expression into the _update_-part of the brb.operations.

```auto
brb.operations(buop -> buop.update(upop -> upop.index("foo").id("bar").doc(r5), Rechnung.class));

```

This results in eclipse telling me "The target type of this expression must be a functional interface". After hours of searching i found

> <https://stackoverflow.com/questions/72025935/how-can-i-create-bulk-crud-operations-request-in-elasticsearch-version-8-using-j>

which tells, that ".doc" does not exist. Eclipse didn't!

**Why is .doc missing?**

Actuall solution (compileable code but gives java.lang.IllegalArgumentException: Class class co.elastic.clients.elasticsearch.core.bulk.UpdateOperation cannot be read from JSON):

```auto
ObjectMapper mapper = new ObjectMapper();
String myjson = mapper.writeValueAsString(r5);
UpdateOperation.Builder<Rechnung, Void> up = new UpdateOperation.Builder<Rechnung, Void>();
up.index("foo");
up.id("bar");
up.withJson(new StringReader(myjson));
BulkOperation bo3 = new BulkOperation.Builder().update(up.build()).build();
brb.operations(bo3);

```

or "short" Lambda:

```auto
brb.operations(buop -> buop.update(upop -> {
ObjectMapper mapper = new ObjectMapper();
String myjson = "";
try {
	myjson = mapper.writeValueAsString(r5);
} catch (JsonProcessingException e) {
	e.printStackTrace();
}
return upop.index("foo").id("bar").withJson(new StringReader(myjson));
}));

```

Well these both are not short and not nice looking.  
**Is there actually a shorter and more nice looking method?**

Thanks - Enomine

---

<div class="post-metadata">

**Author:** ![Michael\_Gattinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_gattinger/32/99690_2.png) [@Michael\_Gattinger](https://discuss.elastic.co/u/Michael_Gattinger)\
**Post date:** [October 28, 2022, 4:15am UTC](https://discuss.elastic.co/t/why-is-doc-missing-in-updateoperation/317587/2 "2022-10-28T04:15:25Z")

</div>

Hey there. Found a working code for me:

```auto
BulkRequest.Builder brb = new BulkRequest.Builder().index(rechnungen10);
Rechnung r6 = new Rechnung();
r6.Rechnungsbetrag = 49.99f;
brb.operations(buop -> buop.update(uo -> uo.id("" + Rechnungsnummer).action(ua -> ua.doc(r6))));

```

Found at [New JAVA API Documentation](https://discuss.elastic.co/t/new-java-api-documentation/299559) -\> [elasticsearch-java/RequestTest.java at main · elastic/elasticsearch-java · GitHub](https://github.com/elastic/elasticsearch-java/blob/main/java-client/src/test/java/co/elastic/clients/elasticsearch/end_to_end/RequestTest.java#L209-L247)

Elasticsearch Java API Client should be more like this skripting thing =) ... How do you call it?

Painless

Thanks - Enomine

---

<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 25, 2022, 4:15am UTC](https://discuss.elastic.co/t/why-is-doc-missing-in-updateoperation/317587/3 "2022-11-25T04:15:44Z")

</div>

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