问题:
在ElasticSearch中安装X-pack后,通过TransportClient进行访问时,需要实例化PreBuiltXPackTransportClient,因此需要加入相应的jar包文件来增加此类。
解决:
Maven构建项目的话:
<project ...>
<repositories>
<repository>
<id>elasticsearch-releases</id>
<url>https://artifacts.elastic.co/maven</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
...
</repositories>
...
<dependencies>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>x-pack-transport</artifactId>
<version>5.2.2</version>
</dependency>
...
</dependencies>
...
</project>
Gradle构建项目的话:
repositories {
/* ... Any other repositories ... */
// Add the Elasticsearch Maven Repository
maven {
url "https://artifacts.elastic.co/maven"
}
}
dependencies {
// Provide the x-pack jar on the classpath for compilation and at runtime
compile "org.elasticsearch.client:x-pack-transport:5.2.2"
/* ... */
}