我提供了以下代码
val conf = new org.apache.spark.SparkConf()
.setMaster("local[*]")
.setAppName("es-example")
.set("es.nodes", "search-2meoihmu.us-est-1.es.amazonaws.com")
val sc = new org.apache.spark.SparkContext(conf)
val resource = "index/data"
val count = sc.esRDD(resource).count()
println(count)
使用,
elastic search version=1.5.2
spark version=1.5.2
Scala version=2.10.4
并给出了库依赖关系,如下所示,
libraryDependencies += "org.elasticsearch" % "elasticsearch-spark_2.10" % "2.1.3"
运行程序时出现以下错误
Exception in thread "main" org.elasticsearch.hadoop.rest.EsHadoopNoNodesLeftException: Connection error (check network and/or proxy settings)- all nodes failed
如何使用spark和Scala从弹性搜索中读取数据?
答案 0 :(得分:1)
请查看“es.nodes.wan.only”选项。默认情况下,此键的值设置为“false”,当我将其设置为true时,该异常消失。以下是配置值的当前文档:https://www.elastic.co/guide/en/elasticsearch/hadoop/current/configuration.html。
val conf = new org.apache.spark.SparkConf()
.setMaster("local[*]")
.setAppName("es-example")
.set("es.nodes", "search-2meoihmu.us-est-1.es.amazonaws.com")
.set("es.nodes.wan.only", "true")
请注意,doc指定将此值翻转为类似于AWS上的环境的true,但在尝试指向运行Elasticsearch的VM时,此异常发生在我身上。