在Elasticsearch版本5.x中删除了DeleteByQueryPlugin,转而使用Delete By Query API。 要迁移到新API,我必须替换2.3代码:
DeleteByQueryResponse response = new DeleteByQueryRequestBuilder(client(), DeleteByQueryAction.INSTANCE)
.setIndices(INDEX_LOCKS)
.setQuery(rangeQuery(EXPIRES_AT).lte(expiresAt))
.execute()
.actionGet();
使用新的5.x DeleteByQueryAction代码:
BulkIndexByScrollResponse response = DeleteByQueryAction.INSTANCE.newRequestBuilder(client())
.filter(rangeQuery(EXPIRES_AT).lte(expiresAt))
.source(INDEX_LOCKS)
.get();
如果我启动服务器并测试代码,这工作正常。但它不适用于我的集成测试。以下测试代码抛出异常:
Testcode:
public class DeleteByQueryTest extends ESIntegTestCase {
private static final String INDEX_LOCKS = "locks";
private static final String INDEX_ARTICLES = "articles";
private static final String LOCK_TYPE = "lock";
private static final String LOCK_ID = "something";
@Before
public void waitForIndex() {
createIndex(INDEX_LOCKS, INDEX_ARTICLES);
ensureGreen(INDEX_LOCKS, INDEX_ARTICLES);
}
@Test
public void shouldDeleteByQuery() {
IndexResponse indexResponse = client().prepareIndex(INDEX_LOCKS, LOCK_TYPE, LOCK_ID).setSource("{}").setCreate(true).get();
assertThat(indexResponse.getId(), is(LOCK_ID));
refresh();
BulkIndexByScrollResponse response = DeleteByQueryAction.INSTANCE.newRequestBuilder(client())
.filter(idsQuery(LOCK_TYPE).addIds(LOCK_ID))
.source(INDEX_LOCKS)
.get();
assertThat(response.getDeleted(), is(1L));
}
}
发生的异常:
java.lang.IllegalStateException: failed to find action [org.elasticsearch.index.reindex.DeleteByQueryAction@5794e1cf] to execute
at __randomizedtesting.SeedInfo.seed([F8694D27C3481CF8:12F0CCE2BD73E437]:0)
at org.elasticsearch.client.node.NodeClient.transportAction(NodeClient.java:100)
at org.elasticsearch.client.node.NodeClient.executeLocally(NodeClient.java:75)
at org.elasticsearch.client.node.NodeClient.doExecute(NodeClient.java:64)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
at org.elasticsearch.client.FilterClient.doExecute(FilterClient.java:67)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62)
at de.sabio.search.indexer.lock.DeleteByQueryTest.shouldDeleteByQuery(DeleteByQueryTest.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1713)
at com.carrotsearch.randomizedtesting.RandomizedRunner$8.evaluate(RandomizedRunner.java:907)
at com.carrotsearch.randomizedtesting.RandomizedRunner$9.evaluate(RandomizedRunner.java:943)
at com.carrotsearch.randomizedtesting.RandomizedRunner$10.evaluate(RandomizedRunner.java:957)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.util.TestRuleSetupTeardownChained$1.evaluate(TestRuleSetupTeardownChained.java:49)
at org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:45)
at org.apache.lucene.util.TestRuleThreadAndTestName$1.evaluate(TestRuleThreadAndTestName.java:48)
at org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:64)
at org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:47)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:367)
at com.carrotsearch.randomizedtesting.ThreadLeakControl.forkTimeoutingTask(ThreadLeakControl.java:811)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$3.evaluate(ThreadLeakControl.java:462)
at com.carrotsearch.randomizedtesting.RandomizedRunner.runSingleTest(RandomizedRunner.java:916)
at com.carrotsearch.randomizedtesting.RandomizedRunner$5.evaluate(RandomizedRunner.java:802)
at com.carrotsearch.randomizedtesting.RandomizedRunner$6.evaluate(RandomizedRunner.java:852)
at com.carrotsearch.randomizedtesting.RandomizedRunner$7.evaluate(RandomizedRunner.java:863)
at org.apache.lucene.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:45)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:41)
at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at org.apache.lucene.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:53)
at org.apache.lucene.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:47)
at org.apache.lucene.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:64)
at org.apache.lucene.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:54)
at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:367)
at java.lang.Thread.run(Thread.java:745)
有没有人遇到同样的问题,知道该怎么做?
答案 0 :(得分:2)
解决方案是在测试代码中添加reindex插件:
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singleton(ReindexPlugin.class);
}
@Override
protected Collection<Class<? extends Plugin>> transportClientPlugins() {
return Collections.singleton(ReindexPlugin.class);
}