gpt4 book ai didi

scala - ElasticClient提供NullPointerException

转载 作者:行者123 更新时间:2023-12-03 00:11:32 26 4
gpt4 key购买 nike

使用Scala 2.11.8和Elasticsearch 2.3.5的本地实例以及以下依赖项:

libraryDependencies ++ = Seq(
"com.sksamuel.elastic4s" %% "elastic4s-core" % "2.3.1",
"org.apache.spark" %% "spark-core" % 1.6.2,
"org.apache.spark" %% "spark-sql" % 1.6.2,
"org.elasticsearch" % "elasticsearch" % 2.4.0,
"org.elasticsearch" %% "elasticsearch-spark" % 2.4.0
)

运行下面的最后一行时,我得到了NullPointerException:
val conf = new SparkConf().setAppName("DataIndexer").setMaster("local[*]")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
val uri = ElasticsearchClientUri("elasticsearch://localhost:9300")
val client = ElasticClient.transport(uri)
client.execute(indexExists(name)).await.isExists

我是Scala / Spark的新手,但未发现有关此错误的任何信息。我认为这很明显,但是我不确定。任何帮助,将不胜感激。

编辑:
这是堆栈跟踪:
Exception in thread "main" java.lang.NullPointerException
at com.unleashbts.thor.ElasticIngestor$.ensureIndex(ElasticIngestor.scala:46)
at com.unleashbts.thor.ElasticIngestor$.ingest(ElasticIngestor.scala:59)
at com.unleashbts.thor.ElasticIngestor$.main(ElasticIngestor.scala:42)
at com.unleashbts.thor.ElasticIngestor.main(ElasticIngestor.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

最佳答案

看起来是因为我在一个单独的类中执行此操作,所以出现了此错误(上面的示例代码不够准确)。我将代码移到了调用execute命令的类中,这解决了我的问题。

关于scala - ElasticClient提供NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40243273/

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