Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ public BulkResponse indexDocuments(String index, List<AirbyteRecordMessage> reco
// TODO: Can we do something like this?
private String extractPrimaryKey(AirbyteRecordMessage doc, ElasticsearchWriteConfig config) {
if (!config.hasPrimaryKey()) {
// Check for _id field if no primary key is configured
// Try uppercase first (Snowflake default), then lowercase fallback
JsonPointer idPtr = JsonPointer.valueOf("/_ID");
var idNode = doc.getData().at(idPtr);
if (idNode.isMissingNode()) {
idPtr = JsonPointer.valueOf("/_id");
idNode = doc.getData().at(idPtr);
}
if (!idNode.isMissingNode() && idNode.isValueNode()) {
log.debug("using _id field value for document id");
return idNode.asText();
}
return UUID.randomUUID().toString();
}
var optFirst = config.getPrimaryKey().stream().findFirst();
Expand All @@ -196,7 +208,19 @@ private String extractPrimaryKey(AirbyteRecordMessage doc, ElasticsearchWriteCon
return pkNode.asText();
}
}
log.warn("unable to extract primary key");
log.warn("unable to extract primary key, checking for _id field");
// Check for _id field as fallback before random UUID
// Try uppercase first (Snowflake default), then lowercase fallback
JsonPointer idPtr = JsonPointer.valueOf("/_ID");
var idNode = doc.getData().at(idPtr);
if (idNode.isMissingNode()) {
idPtr = JsonPointer.valueOf("/_id");
idNode = doc.getData().at(idPtr);
}
if (!idNode.isMissingNode() && idNode.isValueNode()) {
log.debug("using _id field value for document id as fallback");
return idNode.asText();
}
return UUID.randomUUID().toString();
}

Expand Down