# Java API update index

**URL:** <https://discuss.elastic.co/t/java-api-update-index/308928>\
**Category:** Elasticsearch\
**Created:** [July 5, 2022, 2:43pm UTC](https://discuss.elastic.co/t/java-api-update-index/308928 "2022-07-05T14:43:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dorian](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dorian/32/99119_2.png) [@Dorian](https://discuss.elastic.co/u/Dorian)\
**Post date:** [July 5, 2022, 2:43pm UTC](https://discuss.elastic.co/t/java-api-update-index/308928/1 "2022-07-05T14:43:23Z")

</div>

HI everyone, I want to add a new field to a document already indexed.  
I find this in the documentation:

```auto
curl -X POST "localhost:9200/home2/_update/Y_vIvoEB3cv_8tuHzt7j?pretty" -H 'Content-Type: application/json' -d'
{
  "doc": {
    "new field: "test"
  }
}
'

```

But i really don't know how to apply this to the java api.  
If someone can show me how to do it that would be great !

---

<div class="post-metadata">

**Author:** ![garretpremo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/garretpremo/32/108000_2.png) [@garretpremo](https://discuss.elastic.co/u/garretpremo)\
**Post date:** [July 6, 2022, 9:17pm UTC](https://discuss.elastic.co/t/java-api-update-index/308928/2 "2022-07-06T21:17:54Z")

</div>

I'm also interested in learning how to apply this in the Java API.

The `update` method accepts `Class<TDocument>` as an argument. Given that requirement, how can we execute an update request when our document data consists of arbitrary properties (e.g. `Map<String, Object>`)?

---

<div class="post-metadata">

**Author:** ![carton](https://avatars.discourse-cdn.com/v4/letter/c/8baadc/32.png) [@carton](https://discuss.elastic.co/u/carton)\
**Post date:** [July 6, 2022, 9:18pm UTC](https://discuss.elastic.co/t/java-api-update-index/308928/3 "2022-07-06T21:18:43Z")

</div>

Also struggling to find any example code using the new Java API for updates. We store our documents as dynamic json data in Elastic currently, with fields that don't always map out to a specific Java class.

What would the most generic case be for getting data back in a similar format to the one we are used to in the 7.17 high level rest client API?

---

<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:** [August 3, 2022, 9:18pm UTC](https://discuss.elastic.co/t/java-api-update-index/308928/4 "2022-08-03T21:18:50Z")

</div>

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