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

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

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:

request.doc("updated", "hallo",
        "jobStatistics", yourMapHere);
1 Like

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