如何在嵌入式ES 2.3.3中使用DeleteByQuery插件

时间:2016-07-28 12:00:14

标签: elasticsearch

我以嵌入方式运行ES 2.3.3,但由于描述的异常,我无法调用DeleteByQuery操作。我将DeleteByQuery插件添加到我的类路径中,并为我设置了plugin.types设置,但它仍然无效。

My Maven依赖项: <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>2.3.3</version> </dependency> <dependency> <groupId>org.elasticsearch.plugin</groupId> <artifactId>delete-by-query</artifactId> <version>2.3.3</version> </dependency>

我的ES设置:

Settings elasticsearchSettings = Settings.settingsBuilder()
.put("threadpool.index.queue_size", -1)
.put("path.home", options.getDirectory())
.put("plugin.types", DeleteByQueryPlugin.class.getName())
.build();

NodeBuilder builder = NodeBuilder.nodeBuilder();
node = builder.local(true).settings(elasticsearchSettings).node();

调用用于截断索引的操作。

DeleteByQueryRequestBuilder builder = new DeleteByQueryRequestBuilder(node.client(), DeleteByQueryAction.INSTANCE);
            builder.setIndices(indexName).setQuery(QueryBuilders.matchAllQuery()).execute().addListener(new ActionListener<DeleteByQueryResponse>() {
                public void onResponse(DeleteByQueryResponse response) {
                    if (log.isDebugEnabled()) {
                        log.debug("Deleted index {" + indexName + "}. Duration " + (System.currentTimeMillis() - start) + "[ms]");
                    }
                    sub.onCompleted();
                };

                @Override
                public void onFailure(Throwable e) {
                    log.error("Deleting index {" + indexName + "} failed. Duration " + (System.currentTimeMillis() - start) + "[ms]", e);
                    sub.onError(e);
                }
            });

我看到的例外情况:

Caused by: java.lang.IllegalStateException: failed to find action [org.elasticsearch.action.deletebyquery.DeleteByQueryAction@7c1ed3a2] to execute
    at org.elasticsearch.client.node.NodeClient.doExecute(NodeClient.java:56) ~[elasticsearch-2.3.3.jar:2.3.3]
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:359) ~[elasticsearch-2.3.3.jar:2.3.3]

1 个答案:

答案 0 :(得分:3)

我注意到“节点”构建器使用空插件列表调用节点构造函数。我扩展了Node类,以便调用这个(受保护的)构造函数。

&#xA;&#xA;
 公共类ESNode扩展节点{&#xA;&#xA;受保护的ESNode(设置设置,集合&lt; Class&lt;?extends Plugin&gt;&gt;插件){&#xA; super(InternalSettingsPreparer.prepareEnvironment(settings,null),Version.CURRENT,plugins);&#xA; }&#xA;}&#xA;  
&#xA;&#xA;

使用ESNode加载了所有需要的插件。

&#xA;&#xA ;
 设置&lt; Class&lt;? extends Plugin&gt;&gt; classpathPlugins = new HashSet&lt;&gt;();&#xA; classpathPlugins.add(DeleteByQueryPlugin.class);&#XA; node = new ESNode(settings,classpathPlugins).start();&#xA;  
&#xA;&#xA;

这可能不太理想,但到目前为止它工作正常

&#XA;