Spark 3.0 scala.None$ 不是字符串模式的有效外部类型

Spark 3.0 scala.None$ is not a valid external type for schema of string

使用elasticsearch-hadoop库读取空属性的elasticsearch索引时,出现异常

Caused by: java.lang.RuntimeException: scala.None$ is not a valid external type for schema of string

github 中存在开放缺陷,重现步骤相同:https://github.com/elastic/elasticsearch-hadoop/issues/1635

Spark: 3.1.1
Elasticsearch-Hadoop : elasticsearch-spark-30_2.12-7.12.0
Elasticsearch : 2.3.4

通过设置 elasticsearch-hadoop 属性 es.field.read.empty.as.null = no

.option("es.field.read.empty.as.null", "no")

来自 Elasticsearch Link:
es.field.read.empty.as.null(默认是)
elasticsearch-hadoop是否会将空字段视为null。