使用 Java 在 elasticsearch 中更新多个文档。我正在使用 Elasticsearch 2.3.2
Updating multiple documents in elasticsearch using Java. I am using Elasticsearch 2.3.2
我想使用 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" is the id of my document. I would like to update multiple documents with a new field "wiki_collection":true which matches a pattern like "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 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" is the id of my document. I would like to update multiple documents with a new field "wiki_collection":true which matches a pattern like "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
字段是否经过分析。