我是新来的火花。我正在尝试运行将数据加载到Elasticsearch的Spark作业。我从代码中构建了一个胖子罐,并在spark-submit
期间使用了它。
spark-submit \
--class CLASS_NAME \
--master yarn \
--deploy-mode cluster \
--num-executors 20 \
--executor-cores 5 \
--executor-memory 32G \
--jars EXTERNAL_JAR_FILES \
PATH_TO_FAT_JAR
elasticsearch-hadoop
依赖关系的Maven依赖关系是:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-hadoop</artifactId>
<version>5.6.10</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
当我没有在elasticsearch-hadoop
列表中包含EXTERNAL_JAR_FILES
jar文件时,就会出现此错误。
java.lang.ExceptionInInitializerError
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.spark.rdd.CompatUtils
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:344)
at org.elasticsearch.hadoop.util.ObjectUtils.loadClass(ObjectUtils.java:73)
... 26 more
如果我将其包含在EXTERNAL_JAR_FILES
列表中,则会收到此错误。
java.lang.Error: Multiple ES-Hadoop versions detected in the classpath; please use only one
jar:file:PATH_TO_CONTAINER/__app__.jar
jar:file:PATH_TO_CONTAINER/elasticsearch-hadoop-5.6.10.jar
at org.elasticsearch.hadoop.util.Version.<clinit>(Version.java:73)
at org.elasticsearch.hadoop.rest.RestService.createWriter(RestService.java:572)
at org.elasticsearch.spark.rdd.EsRDDWriter.write(EsRDDWriter.scala:58)
at org.elasticsearch.spark.sql.EsSparkSQL$$anonfun$saveToEs$1.apply(EsSparkSQL.scala:97)
at org.elasticsearch.spark.sql.EsSparkSQL$$anonfun$saveToEs$1.apply(EsSparkSQL.scala:97)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
at org.apache.spark.scheduler.Task.run(Task.scala:108)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:338)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
有什么事情需要克服吗?
答案 0 :(得分:1)
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch-hadoop</artifactId>
<version>7.4.2</version>
<scope>provided</scope>
</dependency>
请注意,[<scope>provided</scope>]
然后您可以使用命令:
bin/spark-submit \
--maste local[*] \
--class xxxxx \
--jars https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch-hadoop/7.4.2/elasticsearch-hadoop-7.4.2.jar \
/your/path/xxxx.jar
答案 1 :(得分:0)
通过在我构建的胖罐中不包括elasticserach-hadoop
罐来解决问题。我在依赖项中提到了scope
的{{1}}参数。
provided
答案 2 :(得分:0)
我遇到了这个问题,因为我将项目的构建从SBT更改为POM。在探索。我看到类路径中有两个jar,一个来自.ivy2文件夹,另一个来自.mvn 我从.ivy2中删除了一个,问题消失了。希望对别人有帮助。