尝试启动嵌入式elasticsearch节点时不支持http.type [netty3]

时间:2016-12-21 12:45:20

标签: rest elasticsearch

我知道不建议使用嵌入式Elasticsearch。我只是为了测试目的而尝试它。

我正在尝试启动一个嵌入式Elasticsearch节点,该节点提供以下elasticsearch.yml的配置

# Name for the cluster
cluster.name: elasticsearch
# Name for the embedded node
node.name: EmbeddedESNode
# Path to log files:
path.logs: logs
discovery.zen.ping.unicast.hosts: []
# Disable dynamic scripting
script.inline: false
script.stored: false
script.file: false
transport.type: local
http.type: netty3

我正在使用es 5.1.1,我的代码启动嵌入式节点如下。

    try {
        Settings elasticsearchSetting = Settings.builder()
                // Value for path.home is required for es but will not be used as long as other properties
                // path.logs, path.data and path.conf is set.
                .put(ES_PROPERTY_PATH_HOME, "nullpath")
                .put(ES_PROPERTY_PATH_CONF, confDir)
                .build();
        Node node = new Node(elasticsearchSetting).start();
        logger.info("Embedded Elasticsearch server successfully started ...");

    } catch (Exception e) {
        throw e;
    }

我得到以下痕迹。

java.lang.IllegalStateException: Unsupported http.type [netty3]
    at org.elasticsearch.common.network.NetworkModule.getHttpServerTransportSupplier(NetworkModule.java:194) ~[elasticsearch-5.1.1.jar:5.1.1]
    at org.elasticsearch.node.Node.<init>(Node.java:396) ~[elasticsearch-5.1.1.jar:5.1.1]
    at org.elasticsearch.node.Node.<init>(Node.java:229) ~[elasticsearch-5.1.1.jar:5.1.1]
    at org.elasticsearch.node.Node.<init>(Node.java:225) ~[elasticsearch-5.1.1.jar:5.1.1]
    ... 18 more

我也试过http.type: netty4但到目前为止还没有运气。它在http.enabled:false设置时有效,但我想使用http rest api进行测试。

P.S: 我一直在使用this elasticsearch hadoop类来实现嵌入式es,不幸的是我在http.type上找不到任何文档。

我无法在ES 5.x中启动带有http的嵌入式节点吗? 我在这里做错了什么?

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:5)

如@Bastian所述,问题是传输模块不在类路径中。在es-hadoop嵌入式es实现中,解决方案已经there

private static class PluginConfigurableNode extends Node {
        public PluginConfigurableNode(Settings settings, Collection<Class<? extends Plugin>> classpathPlugins) {
            super(InternalSettingsPreparer.prepareEnvironment(settings, null), classpathPlugins);
        }
}

我们可以将netty3作为插件提供如下。一切都运作良好。

Collection plugins = Arrays.asList(Netty3Plugin.class);
Node node = new PluginConfigurableNode(elasticsearchSetting, plugins).start();

答案 1 :(得分:2)

您需要将模块transport-netty4添加到类路径中:

 <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>transport-netty4-client</artifactId>
        <version>5.1.1</version>
        <scope>test</scope>
 </dependency>

另见my answer here