gpt4 book ai didi

elasticsearch - 使用JAVA Api代码进行多个字段的Elastic Search文档更新的解决方案

转载 作者:行者123 更新时间:2023-12-01 13:33:50 25 4
gpt4 key购买 nike

演示我们如何更新 Elasticsearch 文档上的多个字段的示例

Map<String, Object> updateObject = new HashMap<String, Object>();
updateObject.put("field1", "updated value for fields1");
updateObject.put("field2", "updated value for fields2");
updateObject.put("field3", "updated value for fields3");
Boolean meessage = client.prepareUpdate("indexName","indextype","documentId").setDoc(updateObject).setRefresh(true).execute().actionGet();

indexName 将是您的索引名称IndexType 将是您的索引类型documentId 将是您要更新的 documentIdclient 是您的 JAVA API 的 ElasticSeach 客户端

最佳答案

我认为你的问题是如何使用JAVA api更新多个字段。

为此使用BulkRequestBuilder

BulkRequestBuilder bulkRequest = client.prepareBulk();

bulkRequest.add(client.prepareUpdate("indexName","indextype","documentId")
.setScript("ctx._source.field1=" + newValueField1));

bulkRequest.add(client.prepareUpdate("indexName","indextype","documentId")
.setScript("ctx._source.field2=" + newValueField2));

BulkResponse bulkResponse = bulkRequest.execute().actionGet();

通过此您可以更新文档中的多个值

关于elasticsearch - 使用JAVA Api代码进行多个字段的Elastic Search文档更新的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21405003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com