# Java rest client: update single field within an (sub)object

**URL:** https://discuss.elastic.co/t/java-rest-client-update-single-field-within-an-sub-object/115241
**Category:** Elasticsearch
**Created:** [January 12, 2018, 8:58am UTC](https://discuss.elastic.co/t/java-rest-client-update-single-field-within-an-sub-object/115241 "2018-01-12T08:58:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![asp](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@asp](https://discuss.elastic.co/u/asp)
#### Post date: [January 12, 2018, 8:58am UTC](https://discuss.elastic.co/t/java-rest-client-update-single-field-within-an-sub-object/115241/1 "2018-01-12T08:58:35Z")

</div>

Hi all,

I would like to update a single field from with java highlevel client. If possible I don't want to create the json by myself.

Updating a field located in document root is working. But if I would like to update a field a level lower, it doesn't work / I don't know how to get it working.

the document source which should be updated looks like that:

```
{
    "jobName": "useraction_3",
    "jobIsActive": true,
    "jobStatistics": {
      "lastRun": 0,
      "lastEndTimestampInQuery": 0,
      "isCurrentlyRunning": false,
      "lastRunDurationInSec": 0,
      "nextRun": 0
    },
...

```

I need to update isCurrentlyRunning which is located below jobStatistics.

I tried with following code:

```
Map<String, Object> jsonMap = new HashMap<String, Object>();
jsonMap.put("jobStatistics.isCurrentlyRunning", new Boolean(true));

UpdateRequest request = new UpdateRequest(Constants.getIndexLtsConfig(), Constants.getIndexLtsType(), documentId);
//request.doc(jsonMap); 
request.doc("updated", "hallo",
        "jobStatistics.isCurrentlyRunning", true); 

UpdateResponse response = client.runUpdateRequest(request);

```

If I get the document I get following document source:

```
 "_source": {
    "jobName": "useraction_3",
    "jobIsActive": true,
    "jobStatistics": {
      "lastRun": 0,
      "lastEndTimestampInQuery": 0,
      "isCurrentlyRunning": false,
      "lastRunDurationInSec": 0,
      "nextRun": 0
    },
...
    "jobStatistics.isCurrentlyRunning": true,
    "updated": "hallo"
  }

```

So what I see is that a new field "jobStatistics.isCurrentlyRunning" is created, but that's not what I need.

Please advise.

Thanks, Andreas

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 12, 2018, 10:09am UTC](https://discuss.elastic.co/t/java-rest-client-update-single-field-within-an-sub-object/115241/2 "2018-01-12T10:09:34Z")

</div>

You need to provide a `Map<String, Object>` for the `jobStatistics` field. This map should contain a key/value pair `"isCurrentlyRunning"`/`true`.

So something like:

```auto
request.doc("updated", "hallo",
        "jobStatistics", yourMapHere);

```

---

<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: [February 9, 2018, 10:09am UTC](https://discuss.elastic.co/t/java-rest-client-update-single-field-within-an-sub-object/115241/3 "2018-02-09T10:09:40Z")

</div>

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