@@ -232,6 +232,9 @@ public class ElasticsearchSinkConnectorConfig extends AbstractConfig {
232232 private static final String DROP_INVALID_MESSAGE_DISPLAY = "Drop invalid messages" ;
233233 private static final boolean DROP_INVALID_MESSAGE_DEFAULT = false ;
234234
235+ private static final String USE_AUTOGENERATED_IDS_DISPLAY = "Elasticsearch Generated IDs" ;
236+ private static final boolean USE_AUTOGENERATED_IDS_DEFAULT = false ;
237+
235238 public static final String BEHAVIOR_ON_NULL_VALUES_CONFIG = "behavior.on.null.values" ;
236239 private static final String BEHAVIOR_ON_NULL_VALUES_DOC = "How to handle records with a "
237240 + "non-null key and a null value (i.e. Kafka tombstone records). Valid options are "
@@ -358,7 +361,17 @@ public class ElasticsearchSinkConnectorConfig extends AbstractConfig {
358361 + DATA_STREAM_NAMESPACE_CONFIG + "``}." ;
359362 private static final String DATA_STREAM_DATASET_DISPLAY = "Data Stream Dataset" ;
360363 private static final String DATA_STREAM_DATASET_DEFAULT = "" ;
361-
364+ public static final String USE_AUTO_GENERATED_IDS_CONFIG = "use.autogenerated.ids" ;
365+ private static final String USE_AUTO_GENERATED_IDS_DOC = String .format (
366+ "Whether to use auto-generated Elasticsearch document IDs for insertion requests. "
367+ + "Note that this setting removes exactly once guarantees and message "
368+ + "delivery will be at least once. Only applies if %s is set to %s."
369+ + "When this is set to ``true``, ``%s`` option will also be ignored when "
370+ + "sending data to Elasticsearch" ,
371+ WRITE_METHOD_CONFIG ,
372+ WriteMethod .INSERT ,
373+ IGNORE_KEY_CONFIG
374+ );
362375 public static final String DATA_STREAM_TYPE_CONFIG = "data.stream.type" ;
363376 private static final String DATA_STREAM_TYPE_DOC = String .format (
364377 "Generic type describing the data to be written to data stream. "
@@ -736,6 +749,16 @@ private static void addConversionConfigs(ConfigDef configDef) {
736749 Width .SHORT ,
737750 WRITE_METHOD_DISPLAY ,
738751 new EnumRecommender <>(WriteMethod .class )
752+ ).define (
753+ USE_AUTO_GENERATED_IDS_CONFIG ,
754+ Type .BOOLEAN ,
755+ USE_AUTOGENERATED_IDS_DEFAULT ,
756+ Importance .MEDIUM ,
757+ USE_AUTO_GENERATED_IDS_DOC ,
758+ CONNECTOR_GROUP ,
759+ ++order ,
760+ Width .SHORT ,
761+ USE_AUTOGENERATED_IDS_DISPLAY
739762 );
740763 }
741764
@@ -923,7 +946,8 @@ public boolean shouldDisableHostnameVerification() {
923946 }
924947
925948 public boolean shouldIgnoreKey (String topic ) {
926- return ignoreKey () || ignoreKeyTopics ().contains (topic );
949+ return ignoreKey () || ignoreKeyTopics ().contains (topic )
950+ || (writeMethod ().equals (WriteMethod .INSERT ) && useAutogeneratedIds ());
927951 }
928952
929953 public boolean shouldIgnoreSchema (String topic ) {
@@ -1010,6 +1034,10 @@ public Set<String> ignoreSchemaTopics() {
10101034 return new HashSet <>(getList (IGNORE_SCHEMA_TOPICS_CONFIG ));
10111035 }
10121036
1037+ public boolean useAutogeneratedIds () {
1038+ return getBoolean (USE_AUTO_GENERATED_IDS_CONFIG );
1039+ }
1040+
10131041 public String kerberosUserPrincipal () {
10141042 return getString (KERBEROS_PRINCIPAL_CONFIG );
10151043 }
0 commit comments