我正在尝试从非常旧的Elasticsearch版本迁移到最新版本6.3.0。我发现此链接ElasticSearch TransportClient version 5.6显示了我尝试实现的模式,但无法正常工作:
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.transport.client.PreBuiltTransportClient
trait ElasticSearchClient {
lazy val client: TransportClient = new PreBuiltTransportClient(
Settings.builder()
.put("cluster.name", clusterName)
// etc...
.build())
我得到了错误:
[error] object client is not a member of package org.elasticsearch.transport
[error] import org.elasticsearch.transport.client.PreBuiltTransportClient
[error] ^
我已经尝试了备用import org.elasticsearch.client.transport.PreBuiltTransportClient
,但仍然无法解决。
如果我尝试lazy val client: TransportClient = new TransportClient(
,它会显示class TransportClient is abstract; cannot be instantiated
。
如果我尝试lazy val client: TransportClient = TransportClient.builder().
,它会显示value builder is not a member of object org.elasticsearch.client.transport.TransportClient
。
我找不到与此有关的任何其他文档或帖子,我在问什么是创建TransportClient
对象的正确模式?
答案 0 :(得分:0)
如果您添加到build.sbt文件的libraryDependencies,则答案是上述方法:
"org.elasticsearch.client" % "transport" % "6.3.0"
请注意,将在7.0中弃用TransportClient,并在8.0中将其删除。请改用RestClient。