简体   繁体   中英

How to update nested elasticsearch value via bulkrequest?

We are using AWS Elasticsearch - 7.7 Version

I already followed Update nested field in an index of ElasticSearch with Java API

I have below JSON Elastic Search

 {
    "_index": "product",
    "_type": "_doc",
    "_source": {
        "id": 1,
        "name": "test",
        "properties": [{
            "id": 1,
            "qty": 10
        }]
    }
}

I have below code

 BulkRequest request = new BulkRequest();
 request.add(new UpdateRequest(<ES Endpoint>, 1))
                        .doc(XContentType.JSON, "name", "TEST 1"));
BulkResponse bulkResponse = restClient.bulk(request, RequestOptions.DEFAULT);   

How should I update "properties" value "qty"?

https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.8/java-docs-update.html

You can pass a Map with all fields to update in the doc() call:

Map doc = new HashMap();
doc.put("name", "TEST 1");
doc.put("qty", 12);
request.add(new UpdateRequest("index", 1)
                    .doc(XContentType.JSON, doc));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM