解决方案弹性搜索文档更新多个字段使用JAVA Api代码 [英] Solutions For Elastic Search document Update For Multiple fields using JAVA Api Code

查看:118
本文介绍了解决方案弹性搜索文档更新多个字段使用JAVA Api代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个例子,演示了我们如何更新弹性搜索文档上的多个字段

An exampes that demonstrates how we update multiple fields on elastic search document

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将是您要更新的文档ID
客户端是您的ElasticSeach客户端用于JAVA API

indexName will be your index name IndexType will be your index type documentId will be your documentId which is going to update client is your ElasticSeach client for JAVA API

推荐答案

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

I think your question is how to update multiple fields using 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();

通过这种方式,您可以更新文档

By this you can update multiple values within document

这篇关于解决方案弹性搜索文档更新多个字段使用JAVA Api代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆