简体   繁体   English

在Java测试中创建索引时Elasticsearch本地节点客户端NPE

[英]Elasticsearch local node client NPE when creating index in java test

I am using elasticsearch (v2.3.2/Windows 7) local node to create an index in a java test which is throwing an null pointer exception. 我正在使用elasticsearch(v2.3.2 / Windows 7)本地节点在抛出空指针异常的Java测试中创建索引。

The test code is as follows: 测试代码如下:

CreateIndexResponse response =  esClient.admin().indices().prepareCreate("mytestindex")
       .setSettings(Settings.builder()
               .put("number_of_replicas", 0)
               .put("number_of_shards", 1))
       .execute().actionGet();

I have verified esClient is created by spring and is not null. 我已验证esClient由spring创建,并且不为null。 The code to create the client is: 创建客户端的代码是:

@Bean
public Client localElasticsearchClient() {

    Settings settings = Settings.settingsBuilder()
            .put("path.home", "/tmp/elasticsearch")
            .put("path.data", "/tmp/elasticsearch")
            .build();

    return NodeBuilder.nodeBuilder()
            .local(true)
            .settings(settings)
            .build()
            .client();

}

The stacktrace is as follows: stacktrace如下:

java.lang.NullPointerException
at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction.<init>(TransportMasterNodeAction.java:129)
at org.elasticsearch.action.support.master.TransportMasterNodeAction.doExecute(TransportMasterNodeAction.java:107)
at org.elasticsearch.action.support.master.TransportMasterNodeAction.doExecute(TransportMasterNodeAction.java:51)
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:137)
at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:85)
at org.elasticsearch.client.node.NodeClient.doExecute(NodeClient.java:58)

I saw something here about it but there was no info on how to correct it. 我在这里看到了一些东西,但是没有有关如何更正它的信息。

Actually the answer was implicitly given in this link 实际上,答案是在此链接中 隐式给出的

I was not calling node.start() method ie 我没有在调用node.start()方法,即

return NodeBuilder.nodeBuilder()
        .local(true)
        .settings(settings)
        .build()
        .start()
        .client();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Elasticsearch - 通过 java API 但不是手动创建索引失败 - Elasticsearch - creating index failure when doing it through java API but not manually 在使用Java高级其余客户端批量API创建动态Elasticsearch索引时需要帮助 - Need help in creating dynamic elasticsearch index using Java high level rest client bulk API 通过elasticsearch java客户端更新索引设置 - updating index settings through elasticsearch java client 弹性搜索-在Java中创建节点/索引时出错 - Elastic search - Error when creating node / index in java Java Elasticsearch Client:在Google Cloud VM中从本地连接到ES时引发ConnectException - Java Elasticsearch client: throws ConnectException when connecting from local to ES in Google Cloud VM 创建嵌入式节点时的ElasticSearch异常 - ElasticSearch exception when creating embedded node 在Windows 7中将新JFileChooser创建为本地系统帐户时Win32ShellFolder2.access中的NPE - NPE in Win32ShellFolder2.access when creating new JFileChooser as Local System Account in Windows 7 使用Java加载文件时的NPE - NPE when loading a file in Java MapperParsingException创建ElasticSearch索引 - MapperParsingException creating elasticsearch index ElasticSearch-使用Java HighLevel HTTP客户端删除索引 - ElasticSearch - Delete an Index using Java HighLevel HTTP Client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM