Skip to content

Commit

Permalink
Merge pull request #21 from zilliztech/test
Browse files Browse the repository at this point in the history
support vector type for elastic search
  • Loading branch information
nianliuu authored Nov 7, 2024
2 parents 78120e5 + 863a1ac commit 8aa6c9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import static org.apache.seatunnel.connectors.seatunnel.elasticsearch.client.EsType.TEXT;
import static org.apache.seatunnel.connectors.seatunnel.elasticsearch.client.EsType.TOKEN_COUNT;
import static org.apache.seatunnel.connectors.seatunnel.elasticsearch.client.EsType.UNSIGNED_LONG;
import static org.apache.seatunnel.connectors.seatunnel.elasticsearch.client.EsType.VECTOR;
import static org.apache.seatunnel.connectors.seatunnel.elasticsearch.client.EsType.VERSION;

@AutoService(TypeConverter.class)
Expand Down Expand Up @@ -105,6 +106,7 @@ public Column convert(BasicTypeDefine<EsType> typeDefine) {
.toArray(SeaTunnelDataType<?>[]::new)));
break;
case DENSE_VECTOR:
case VECTOR:
String elementType =
typeDefine.getNativeType().getOptions().get("element_type").toString();
if (elementType.equals("byte")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.http.Header;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.message.BasicHeader;
import static org.apache.seatunnel.connectors.seatunnel.elasticsearch.client.EsType.VECTOR;
import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode;
import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ArrayNode;
Expand Down Expand Up @@ -666,6 +667,19 @@ private static Map<String, BasicTypeDefine<EsType>> getFieldTypeMappingFromPrope
// es dense_vector dim
typeDefine.scale(fieldProperty.get("dims").asInt());

} else if (type.equalsIgnoreCase(VECTOR)) {
//adapt for huawei cloud elastic search
String elementType =
fieldProperty.get("dim_type") == null
? "float"
: fieldProperty.get("dim_type").asText();
Map<String, Object> options = new HashMap<>();
options.put("element_type", elementType);
typeDefine.nativeType(new EsType(type, options));

// es dense_vector dim
typeDefine.scale(fieldProperty.get("dimension").asInt());

} else if (type.equalsIgnoreCase(DATE)
|| type.equalsIgnoreCase(DATE_NANOS)) {
String format =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class EsType {
public static final String DATE = "date";
public static final String DATE_NANOS = "date_nanos";
public static final String DENSE_VECTOR = "dense_vector";
public static final String VECTOR = "vector";
public static final String DOUBLE = "double";
public static final String FLATTENED = "flattened";
public static final String FLOAT = "float";
Expand Down

0 comments on commit 8aa6c9c

Please sign in to comment.