我在5.1.1版本中编写了自己的内存中ElasticSearch服务器。它适用于添加文档但无法删除。
Maven依赖项:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>5.1.1</version>
<scope>test</scope>
</dependency>
节点的设置地图:
settingsMap.put("node.name", nodeName);
settingsMap.put("path.conf", "target");
settingsMap.put("path.data", "target");
settingsMap.put("path.logs", "target");
settingsMap.put("path.home", "target");
settingsMap.put("http.type", "netty4");
settingsMap.put("http.port", httpPort);
settingsMap.put("transport.tcp.port", httpTransportPort);
settingsMap.put("transport.type", "netty4");
settingsMap.put("action.auto_create_index", "false");
一次删除多个文档的方法:
public boolean deleteType() throws IOException, CustomResponseException {
String query = "{\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " }\n" + "}";
HttpEntity entity = new NStringEntity(query, ContentType.APPLICATION_JSON);
Response indexResponse = restClient.performRequest("POST",
"/" + this.getIndex() + "/" + this.getType() + "/_delete_by_query?conflicts=proceed",
Collections.<String, String>emptyMap(), entity);
return processStatusCode(indexResponse.getStatusLine()) == 200;
}
当我运行测试时,我收到错误:
org.elasticsearch.client.ResponseException:POST http://localhost:9205/testindexer/indexer/_delete_by_query?conflicts=proceed:HTTP / 1.1 400错误请求 {&#34;错误&#34; {&#34; ROOT_CAUSE&#34;:[{&#34;类型&#34;:&#34; illegal_argument_exception&#34;&#34;理由&#34;:& #34;请求[/ testindexer / indexer / _delete_by_query]包含无法识别的参数:[conflicts]&#34;}],&#34; type&#34;:&#34; illegal_argument_exception&#34;,&#34; reason&# 34;:&#34;请求[/ testindexer / indexer / _delete_by_query]包含无法识别的参数:[冲突]&#34;},&#34;状态&#34;:400}
此外,当我在没有冲突的情况下运行它时,我得到了创建文档的答案。为什么它的工作方式与此版本的文档不同?
以下是我的节点的状态:
{
"name" : "indexernode",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "trP6UQg1SMKVyfR0qTEjYw",
"version" : {
"number" : "5.1.1",
"build_hash" : "5395e21",
"build_date" : "2016-12-06T12:36:15.409Z",
"build_snapshot" : false,
"lucene_version" : "6.3.0"
},
"tagline" : "You Know, for Search"
}
答案 0 :(得分:0)
旁注:这不是删除所有索引数据的正确方法,但我猜你已经知道了。
您是否可以尝试将restclient中的参数作为参数提供,而不是作为URL的一部分提供,jsut以确保这不是问题。
我认为这里的主要问题是,你说你正在运行自己的弹性搜索嵌入版本(这就是你在内存中的意思)。您是否检查过reindex插件是否安装了该版本?