FAQ-来源ES时出现类型转换失败,不支持来源字段名特殊符号 等错误
更新时间: 2025-11-07 10:47:05
阅读 22
FAQ-来源ES时出现类型转换失败,不支持来源字段名特殊符号 等错误
问题简述
来源ES时出现类型转换失败,不支持来源字段名带特殊符号,scala. MatchError,can not cast to错误等关键字
elasticsearch,来源表,类型转换失败,字段名不支持特殊符号,scala. MatchError,can not cast to任务类型
数据传输来源数据源类型
来源es,elasticsearch去向数据源类型
不限关键异常堆栈
scala. MatchError: Buffer(4) (of class scala. collection. convert.Wrappers$JListWrapper)
2025-03-28 13:43:01 CST SparkExecutor ERROR - Diagnostics: User class threw exception: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 0.0 failed 4 times, most recent failure: Lost task 0.3 in stage 0.0 (TID 9) (vwatjsfdatapf06.ap.vwg executor 1): org.elasticsearch.hadoop.rest.EsHadoopParsingException: org.elasticsearch.hadoop.EsHadoopIllegalStateException: Found field 'BodyVariables.item.deviceID'. Fields containing dots ('.') are not supported in es-hadoop
Caused by: com.alibaba.fastjson.JSONException: can not cast to Date, value: 2024-09
原因与解决方法
出现类型转换失败,一般是由于来源es index中有脏数据与es本身mapping定义不符合,这时候如果使用的是系统推断类型模式(spark es connector),则会报错。建议的解决方案:
方案一、修复index中的脏数据
方案二、改用读取为String类型模型,这种模式下不使用spark es connector,会把所有字段值都当做string读则基本不会报错。如果还出现can not cast to,则修改es mapping定义,将报错的es字段类型改为String (source.sourceSchemaMap={"id":"string", "column2":"string"},注意使用sourceSchemaMap时要把所有需要的来源字段都写上)
出现不支持来源字段名带特殊符号,读取复杂类型报scala. MatchError错误时,一般是出现在使用了系统推断类型模式(spark es connector),spark es connector对类型和字段名有限制,建议的解决方案:
1、改用读取为String类型模型,这样将复杂类型直接读取成String写到下游后再做处理
2、对于需要在传输中直接提取嵌套字段,并且嵌套字段还带有特殊符号,则可以使用自定义表达式,例如get_json_object(BodyVariables, "$.BodyVariables['item.deviceID_1']")
作者:lilingwei01
文档反馈
以上内容对您是否有帮助?