我在使用Maven 的Java 项目中使用Elasticsearch:
...
<elasticsearch.version>6.7.0</elasticsearch.version>
...
<!-- Elasticsearch -->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.8.2</version>
</dependency>
<!-- Elasticsearch -->
当我尝试初始化 TransportClient 以便为文档编制索引时,出现错误:
NoNodeAvailableException[None of the configured nodes are available:
[{#transport#-1}{BHMBbfcrSUOM_Pyaf1LcnA}{localhost}{127.0.0.1:9300}]]
也许需要在 config/elasticsearch.yaml 中添加更多关于传输的信息,或者当前配置是错误的。
Java代码:
TransportAddress address;
TransportClient client;
Settings settings;
try {
address = new TransportAddress(InetAddress.getByName("localhost"), 9300);
settings = Settings
.builder()
.put("cluster.name", "lib2life")
.put("client.transport.sniff", true)
.build();
/* Initiate Transport Client */
client = new PreBuiltTransportClient(settings)
.addTransportAddress(address);
}
神不在的星期二
精慕HU
相关分类