简体   繁体   English

使用Java NodeClient时重新索引elasticsearch 2.3.3

[英]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: 感兴趣的依存关系:

  • org.elasticsearch:elasticsearch:2.3.3 org.elasticsearch:elasticsearch:2.3.3
  • org.elasticsearch.module:reindex:2.3.3 org.elasticsearch.module:reindex:2.3.3
  • org.apache.lucene:lucene-expressions:5.5.1 org.apache.lucene:lucene-expressions:5.5.1
  • org.codehaus.groovy:groovy:2.4.6 org.codehaus.groovy:groovy:2.4.6

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.

相关问题 MasterNotDiscoveredException-使用NodeClient连接到使用dyanamic ip在机器上运行的elasticsearch - MasterNotDiscoveredException - connecting to elasticsearch running on machine with dyanamic ip using NodeClient 使用Java中的elasticSearch 2.3.3按索引名称和类型删除索引 - Delete Indexes by index name and type using elasticSearch 2.3.3 in java 如何通过 Java API 在 ElasticSearch 中重新索引 - How to reindex in ElasticSearch via Java API ElasticSearch ReIndex 请求未使用 Java Rest 高级客户端以同步方式工作 - ElasticSearch ReIndex Request not working in synchronous manner using Java Rest High Level Client 如何使用 java 高级别 rest3A84DEFA4886DAFCE6A4E7AE63A3BAEED443C48Z 在 elasticsearch 中知道是成功还是失败 - How to know if a reindex from remote task is sucessful or failed in elasticsearch using the java high level rest API FusionAuth 使用 AWS Elasticsearch 不完全重新索引 - FusionAuth incomplete reindex with AWS Elasticsearch 使用 java 中的 Rest 高级客户端重新索引选定的 _source 字段 - Reindex selected _source fields using Rest high level client in java 使用Java API时如何在ElasticSearch中使用特定的分析器 - How to use a specific analyser in ElasticSearch when using Java API Elasticsearch 仅重新索引某些 _source 参数 - Elasticsearch reindex only certain _source parameters Elasticsearch 索引是重新索引完成后的“快照” - Elasticsearch index is 'snapshot' after reindex finish
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM