[英]Reindex elasticsearch 2.3.3 when using Java NodeClient
With the deprecation of SearchTye.SCAN
and the newly Reindex API we want to migrate our elasticsearch cluster and clients from 2.1.1 to 2.3.3. 随着
SearchTye.SCAN
和新的Reindex API的弃用,我们希望将我们的Elasticsearch集群和客户端从2.1.1迁移到2.3.3。
We use java and the appropiate libraries to access elasticsearch. 我们使用java和适当的库来访问elasticsearch。 To access the cluster we use the TransportClient, for embedded Unittests we use the NodeClient.
要访问群集,我们使用TransportClient,对于嵌入式单元测试,我们使用NodeClient。
Unfortunatly the Reindex API is provided as plugin, which the NodeClient seems to be unable to deal with. 不幸的是,Reindex API是作为插件提供的,NodeClient似乎无法处理。
So the question is how to use the NodeClient with the Reindex-Plugin? 那么问题是如何将NodeClient与Reindex-Plugin一起使用?
I already tried exposing the protected NodeClient constructor to pass the ReindexPlugin class as argument without success. 我已经尝试公开受保护的NodeClient构造函数以将ReindexPlugin类作为参数传递而没有成功。
Using the NodeClient to start an embedded ElasticSearch and using the TransportClient with the added ReindexPlugin didn't worked either. 使用NodeClient启动嵌入式ElasticSearch以及将TransportClient与添加的ReindexPlugin一起使用均无效。 All I get here is an Exception:
ActionNotFoundTransportException[No handler for action [indices:data/write/reindex]]
我得到的只是一个异常:
ActionNotFoundTransportException[No handler for action [indices:data/write/reindex]]
Dependencies of interest: 感兴趣的依存关系:
Starting the NodeClient: 启动NodeClient:
Settings.Builder settings = Settings.settingsBuilder();
settings.put("path.data", "/some/path/data");
settings.put("path.home", "/some/path/home");
//settings.put("plugin.types", ReindexPlugin.class.getName()); > No effect
settings.put("http.port", 9299);
settings.put("transport.tcp.port", 9399);
node = NodeBuilder.nodeBuilder()
.clusterName("testcluster")
.settings(settings)
.local(true)
.node();
// also tested with local(false), then no transport port is available, resulting in NoNodeAvailableException
Using TransportClient to access the Node: 使用TransportClient访问节点:
Settings settings = Settings.settingsBuilder()
.put("cluster.name", "testcluster")
.put("discovery.zen.ping.multicast.enabled", false)
.build();
InetSocketTransportAddress[] addresses = new InetSocketTransportAddress[]
{new InetSocketTransportAddress(new InetSocketAddress("localhost", 9399))};
client = TransportClient.builder()
.settings(settings)
.addPlugin(ReindexPlugin.class)
.build()
.addTransportAddresses(addresses);
Main part of triggering reindex: 触发重新索引的主要部分:
ReindexRequestBuilder builder = ReindexAction.INSTANCE.newRequestBuilder(getClient())
.source(indexFrom)
.destination(indexTo)
.refresh(true);
I was able to solve this, by combining both approaches described above. 通过结合上述两种方法,我能够解决此问题。
So creating the NodeClient involves overriding the Node: 因此,创建NodeClient涉及覆盖Node:
class ExposedNode extends Node {
public ExposedNode(Environment tmpEnv, Version version, Collection<Class<? extends Plugin>> classpathPlugins) {
super(tmpEnv, version, classpathPlugins);
}
}
And using it when starting the NodeClient: 并在启动NodeClient时使用它:
Settings.Builder settings = Settings.settingsBuilder();
settings.put("path.data", "/some/path/data");
settings.put("path.home", "/some/path/home");
settings.put("http.port", 9299);
settings.put("transport.tcp.port", 9399);
// Construct Node without NodeBuilder
List<Class<? extends Plugin>> classpathPlugins = ImmutableList.of(ReindexPlugin.class);
settings.put("node.local", false);
settings.put("cluster.name", "testcluster");
Settings preparedSettings = settings.build();
node = new ExposedNode(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), Version.CURRENT, classpathPlugins);
node.start();
After that you can use the TransportClient which adds the ReindexPlugin, as described in the question. 之后,您可以使用TransportClient来添加ReindexPlugin,如问题中所述。
Nevertheless this is a dirty hack, which may break in a future release, and shows how poorly Elasticsearch supports plugin development imo. 尽管如此,这是一个肮脏的技巧,可能会在将来的版本中打破,并且表明Elasticsearch对插件开发imo的支持程度很差。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.