elasticclient提供nullpointerexception

w6lpcovy  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(367)

使用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)
toiithl6

toiithl61#

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

相关问题