启动 Elastic Transport 客户端时出错 - 不受支持 transport.type [netty4]

Error on starting Elastic Transport client - Unsupported transport.type [netty4]

我正在将代码从 elastic 5 迁移到 7

pom 中的弹性依赖:

 <elastic.version>7.12.1</elastic.version>

 <dependency>
  <groupId>org.elasticsearch</groupId>
  <artifactId>elasticsearch</artifactId>
  <version>${elastic.version}</version>
</dependency>

<dependency>
  <groupId>org.elasticsearch.client</groupId>
  <artifactId>transport</artifactId>
  <version>${elastic.version}</version>
</dependency>

<dependency>
  <groupId>org.elasticsearch.client</groupId>
  <artifactId>elasticsearch-rest-high-level-client</artifactId>
  <version>${elastic.version}</version>
</dependency>

客户端初始化看起来像这样:

val settings = Settings.builder()
  .put("cluster.name", cluster)
  .put("client.transport.sniff", true)
  .build()

val clientBase:TransportClient = new PreBuiltTransportClient(settings)
val client = hosts.foldLeft(clientBase)((c,h) =>
  c.addTransportAddress(new TransportAddress(InetAddress.getByName(h), port))
)

当运行代码出现以下错误:

 Caused by: java.lang.IllegalStateException: Unsupported transport.type [netty4]
at org.elasticsearch.common.network.NetworkModule.getTransportSupplier(NetworkModule.java:201)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:186)
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:282)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:119)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:105)
at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:95)

请告知如何修复它

看来您需要添加 transport-netty4-client 作为依赖项,请参阅