Skip to content

Commit 84f10f2

Browse files
iture123iture123
andauthored
[Bug][Connector-V2][ES]Fix es field type not support binary(#4240) (#4274)
Co-authored-by: iture123 <iture123@163.com>
1 parent 6b7c81d commit 84f10f2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/constant/EsTypeMappingSeaTunnelType.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.apache.seatunnel.api.table.type.BasicType;
2121
import org.apache.seatunnel.api.table.type.LocalTimeType;
2222
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
23+
import org.apache.seatunnel.connectors.seatunnel.elasticsearch.exception.ElasticsearchConnectorErrorCode;
24+
import org.apache.seatunnel.connectors.seatunnel.elasticsearch.exception.ElasticsearchConnectorException;
2325

2426
import java.util.HashMap;
2527
import java.util.Map;
@@ -32,6 +34,7 @@ public class EsTypeMappingSeaTunnelType {
3234
put("string", BasicType.STRING_TYPE);
3335
put("keyword", BasicType.STRING_TYPE);
3436
put("text", BasicType.STRING_TYPE);
37+
put("binary", BasicType.STRING_TYPE);
3538
put("boolean", BasicType.BOOLEAN_TYPE);
3639
put("byte", BasicType.BYTE_TYPE);
3740
put("short", BasicType.SHORT_TYPE);
@@ -44,7 +47,19 @@ public class EsTypeMappingSeaTunnelType {
4447
}
4548
};
4649

50+
/**
51+
* if not find the mapping SeaTunnelDataType will throw runtime exception
52+
*
53+
* @param esType
54+
* @return
55+
*/
4756
public static SeaTunnelDataType getSeaTunnelDataType(String esType) {
48-
return MAPPING.get(esType);
57+
SeaTunnelDataType seaTunnelDataType = MAPPING.get(esType);
58+
if (seaTunnelDataType == null) {
59+
throw new ElasticsearchConnectorException(
60+
ElasticsearchConnectorErrorCode.ES_FIELD_TYPE_NOT_SUPPORT,
61+
String.format("elasticsearch type is %s", esType));
62+
}
63+
return seaTunnelDataType;
4964
}
5065
}

seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/exception/ElasticsearchConnectorErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public enum ElasticsearchConnectorErrorCode implements SeaTunnelErrorCode {
2828
LIST_INDEX_FAILED("ELASTICSEARCH-05", "List elasticsearch index failed"),
2929
DROP_INDEX_FAILED("ELASTICSEARCH-06", "Drop elasticsearch index failed"),
3030
CREATE_INDEX_FAILED("ELASTICSEARCH-07", "Create elasticsearch index failed"),
31+
ES_FIELD_TYPE_NOT_SUPPORT("ELASTICSEARCH-08", "Not support the elasticsearch field type");
3132
;
3233

3334
private final String code;

0 commit comments

Comments
 (0)