我想使用 Java Api 更新特定字段的一些索引数据。我已引用此文档https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-update.html并创建了一个java程序。我的 Java 程序如下所示:
public class App {
public static void main(String[] args) throws Exception {
Client client = TransportClient.builder().build().addTransportAddress(
new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"),
9300));
UpdateRequest updateRequest = new UpdateRequest("pibindex", "SearchTech",
"http://www.sea.com/bundle")
.script(new Script("ctx._source.default_collection = \"true\""));
client.update(updateRequest).get();
}
}
该程序正在根据脚本更新单个文档。 “pibindex”是我的索引的名称,“SearchTech”是我的索引的类型,“http://www.sea.com/bundle”是我的文档的ID。我想使用新字段“wiki_collection”更新多个文档:true 与“http://www.sea.com/bundle”等模式匹配。我想使用通配符查询。
我正在尝试用 Java 实现这个 elasticsearch 查询:
POST /pibindex2/_update_by_query
{
"script": {
"inline": "ctx._source.wiki_collection=true"
},
"query": {
"wildcard": {
"url": {
"value": "http://www.sea.com/bundle/*"
}
}
}
}
抱歉,如果我遗漏了一些明显的东西。谢谢。
最佳答案
您可以尝试以下方法:
import static org.elasticsearch.index.query.QueryBuilders.wildcardQuery;
BulkIndexByScrollResponse r = ubqrb.source("twitter")
.script(script)
.filter(wilcardQuery("url", "http://www.sea.com/bundle/*"))
.get();
尽管结果取决于您的 url
字段是否被分析。
关于java - 使用 Java 更新 elasticsearch 中的多个文档。我正在使用 Elasticsearch 2.3.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37197888/