@@ -332,29 +332,46 @@ public class ElasticsearchSinkConnectorConfig extends AbstractConfig {
332332 private static final String KERBEROS_KEYTAB_PATH_DEFAULT = null ;
333333
334334 // Data stream configs
335+ public static final String DATA_STREAM_NAMESPACE_CONFIG = "data.stream.namespace" ;
336+ private static final String DATA_STREAM_NAMESPACE_DOC =
337+ "Generic name describing user-configurable arbitrary grouping to be written to a data "
338+ + "stream. Can be any arbitrary string that is no longer than 100 characters, "
339+ + " is in all lowercase, and does not contain spaces or any of these special characters "
340+ + "``/\\ *\" <>|,#:-``. Otherwise, no value indicates the connector will write to regular "
341+ + "indices instead. If set, this configuration will be used alongside "
342+ + "``data.stream.type`` and ``data.stream.dataset`` to construct the data stream name in"
343+ + "the form of {``data.stream.type``}-{``data.stream.dataset``}-{``"
344+ + DATA_STREAM_NAMESPACE_CONFIG + "``}. "
345+ + "Defaut value is ``${topic}``, that is to say the topic name." ;
346+ private static final String DATA_STREAM_NAMESPACE_DISPLAY = "Data Stream Namespace" ;
347+ private static final String DATA_STREAM_NAMESPACE_DEFAULT = "${topic}" ;
348+
335349 public static final String DATA_STREAM_DATASET_CONFIG = "data.stream.dataset" ;
336350 private static final String DATA_STREAM_DATASET_DOC =
337351 "Generic name describing data ingested and its structure to be written to a data stream. Can "
338352 + "be any arbitrary string that is no longer than 100 characters, is in all lowercase, "
339353 + "and does not contain spaces or any of these special characters ``/\\ *\" <>|,#:-``. "
340354 + "Otherwise, no value indicates the connector will write to regular indices instead. "
341- + "If set, this configuration will be used alongside ``data.stream.type`` to "
342- + "construct the data stream name in the form of {``data.stream.type``"
343- + "}-{``" + DATA_STREAM_DATASET_CONFIG + "``}-{topic}." ;
355+ + "If set, this configuration will be used alongside ``data.stream.type`` and "
356+ + "``" + DATA_STREAM_NAMESPACE_CONFIG + "`` to construct the data stream name in "
357+ + "the form of {``data.stream.type``}-{``" + DATA_STREAM_DATASET_CONFIG + "``}-{``"
358+ + DATA_STREAM_NAMESPACE_CONFIG + "``}." ;
344359 private static final String DATA_STREAM_DATASET_DISPLAY = "Data Stream Dataset" ;
345360 private static final String DATA_STREAM_DATASET_DEFAULT = "" ;
346-
361+
347362 public static final String DATA_STREAM_TYPE_CONFIG = "data.stream.type" ;
348363 private static final String DATA_STREAM_TYPE_DOC = String .format (
349364 "Generic type describing the data to be written to data stream. "
350365 + "The default is %s which indicates the connector will write "
351366 + "to regular indices instead. If set, this configuration will "
352- + "be used alongside %s to construct the data stream name in the form of "
353- + "{``%s``}-{``%s``}-{topic }." ,
367+ + "be used alongside %s and %s to construct the data stream name in the form of "
368+ + "{``%s``}-{``%s``}-{``%s`` }." ,
354369 DataStreamType .NONE .name (),
355370 DATA_STREAM_DATASET_CONFIG ,
371+ DATA_STREAM_NAMESPACE_CONFIG ,
356372 DATA_STREAM_TYPE_CONFIG ,
357- DATA_STREAM_DATASET_CONFIG
373+ DATA_STREAM_DATASET_CONFIG ,
374+ DATA_STREAM_NAMESPACE_CONFIG
358375 );
359376 private static final String DATA_STREAM_TYPE_DISPLAY = "Data Stream Type" ;
360377 private static final DataStreamType DATA_STREAM_TYPE_DEFAULT = DataStreamType .NONE ;
@@ -820,6 +837,17 @@ private static void addDataStreamConfigs(ConfigDef configDef) {
820837 int order = 0 ;
821838 configDef
822839 .define (
840+ DATA_STREAM_NAMESPACE_CONFIG ,
841+ Type .STRING ,
842+ DATA_STREAM_NAMESPACE_DEFAULT ,
843+ new DataStreamNamespaceValidator (),
844+ Importance .LOW ,
845+ DATA_STREAM_NAMESPACE_DOC ,
846+ DATA_STREAM_GROUP ,
847+ ++order ,
848+ Width .MEDIUM ,
849+ DATA_STREAM_NAMESPACE_DISPLAY
850+ ).define (
823851 DATA_STREAM_DATASET_CONFIG ,
824852 Type .STRING ,
825853 DATA_STREAM_DATASET_DEFAULT ,
@@ -946,6 +974,10 @@ public String dataStreamDataset() {
946974 return getString (DATA_STREAM_DATASET_CONFIG );
947975 }
948976
977+ public String dataStreamNamespace () {
978+ return getString (DATA_STREAM_NAMESPACE_CONFIG );
979+ }
980+
949981 public DataStreamType dataStreamType () {
950982 return DataStreamType .valueOf (getString (DATA_STREAM_TYPE_CONFIG ).toUpperCase ());
951983 }
@@ -1078,6 +1110,45 @@ public WriteMethod writeMethod() {
10781110 return WriteMethod .valueOf (getString (WRITE_METHOD_CONFIG ).toUpperCase ());
10791111 }
10801112
1113+ private static class DataStreamNamespaceValidator implements Validator {
1114+
1115+ @ Override
1116+ @ SuppressWarnings ("unchecked" )
1117+ public void ensureValid (String name , Object value ) {
1118+ if (value == null ) {
1119+ return ;
1120+ }
1121+
1122+ String namespace = (String ) value ;
1123+
1124+ if (namespace .length () > 100 ) {
1125+ throw new ConfigException (
1126+ name , namespace , "The specified namespace must be no longer than 100 characters."
1127+ );
1128+ }
1129+
1130+ if (!namespace .equals (namespace .toLowerCase ())) {
1131+ throw new ConfigException (
1132+ name , namespace , "The specified namespace must be in all lowercase."
1133+ );
1134+ }
1135+
1136+ if (namespace .matches (".*[\\ \\ \\ /\\ *\\ ?\\ \" <>| ,#\\ -:]+.*" )) {
1137+ throw new ConfigException (
1138+ name , namespace ,
1139+ "The specified namespace must not contain any spaces or "
1140+ + "invalid characters \\ /*?\" <>|,#-:"
1141+ );
1142+ }
1143+ }
1144+
1145+ @ Override
1146+ public String toString () {
1147+ return "A valid namespace name that is all lowercase, less than 100 characters, and "
1148+ + "does not contain any spaces or invalid characters \\ /*?\" <>|,#-:" ;
1149+ }
1150+ }
1151+
10811152 private static class DataStreamDatasetValidator implements Validator {
10821153
10831154 @ Override
0 commit comments