gpt4 book ai didi

scala - 通过 TcpClient.transport 连接时出现 elastic4s NoNodeAvailableException

转载 作者:行者123 更新时间:2023-11-29 02:56:48 26 4
gpt4 key购买 nike

我正在尝试通过给定的示例之一来了解 elastic4s here

但是当我尝试通过 TcpClient.transport 连接时,我不断收到以下异常:

Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{IFyYWnE_S4aHRVxT9v60LQ}{dockerhost}{192.168.99.100:9300}]]

我正在尝试连接到 docker 上的弹性实例,elastic 版本是 2.3.4

这是我的依赖项下的代码。

import com.sksamuel.elastic4s.{ElasticClient, ElasticsearchClientUri, TcpClient}
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy
import org.elasticsearch.common.settings.Settings
import com.sksamuel.elastic4s.ElasticDsl._


object Main extends App {
//val settings = Settings.builder().put("cluster.name", "elasticsearch").build()
val client = TcpClient.transport(ElasticsearchClientUri("elasticsearch://dockerhost:9300"))

client.execute {
bulk(
indexInto("myindex" / "mytype").fields("country" -> "Mongolia", "capital" -> "Ulaanbaatar"),
indexInto("myindex" / "mytype").fields("country" -> "Namibia", "capital" -> "Windhoek")
).refresh(RefreshPolicy.WAIT_UNTIL)
}.await

val result = client.execute {
search("myindex").matchQuery("capital", "ulaanbaatar")
}.await

println(result.hits.head.sourceAsString)

client.close()
}

build.gradle:

compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-core_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-tcp_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-http_2.11', version: '5.4.9'
compile group: 'com.sksamuel.elastic4s', name: 'elastic4s-streams_2.11', version: '5.4.9'

有关此问题的任何帮助都会有所帮助。

最佳答案

我经常被问到这个问题,99% 的时候,这个问题的答案是

  1. 集群名称不是默认的 (elasticsearch),因此必须在连接字符串中指定。

  2. 服务器未设置为在本地主机之外监听。 https://www.elastic.co/blog/elasticsearch-unplugged

关于scala - 通过 TcpClient.transport 连接时出现 elastic4s NoNodeAvailableException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45577077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com