Skip to content

Commit 38cbb38

Browse files
committed
Encorporating feedback
1 parent 51b4ed6 commit 38cbb38

File tree

7 files changed

+24
-20
lines changed

7 files changed

+24
-20
lines changed

modules/data-streams/src/yamlRestTest/resources/rest-api-spec/test/data_stream/240_logs_ecs_mappings.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ Test Elastic Agent log ECS mappings:
111111
"stream": "stderr",
112112
"data_stream": {
113113
"namespace": "default",
114-
"type": "logs",
115114
"dataset": "kubernetes.container_logs"
116115
},
117116
"host": {
@@ -276,7 +275,7 @@ Test general mockup ECS mappings:
276275
"data_stream": {
277276
"dataset": "nginx.access",
278277
"namespace": "production",
279-
"type": "logs"
278+
"custom": "whatever"
280279
},
281280
"structured_data": {
282281
"key1": "value1",
@@ -312,6 +311,10 @@ Test general mockup ECS mappings:
312311
fields:
313312
- field: 'start_timestamp'
314313
- field: 'start-timestamp'
314+
script_fields:
315+
data_stream_type:
316+
script:
317+
source: "doc['data_stream.type'].value"
315318
- length: { hits.hits: 1 }
316319
# the ECS date dynamic template enforces mapping of "*_timestamp" fields to a date type
317320
- length: { hits.hits.0._ignored: 2 }
@@ -320,6 +323,8 @@ Test general mockup ECS mappings:
320323
- match: { hits.hits.0.ignored_field_values.start_timestamp.0: 'not a date' }
321324
# "start-timestamp" doesn't match the ECS dynamic mapping pattern "*_timestamp"
322325
- match: { hits.hits.0.fields.start-timestamp.0: 'not a date' }
326+
# verify that data_stream.type has the correct constant_keyword value
327+
- match: { hits.hits.0.fields.data_stream_type.0: 'logs' }
323328
- match: { hits.hits.0._ignored.1: 'vulnerability.textual_score' }
324329

325330
- do:
@@ -381,6 +386,8 @@ Test general mockup ECS mappings:
381386
- match: { .$idx0name.mappings.properties.data_stream.properties.dataset.type: "constant_keyword" }
382387
- match: { .$idx0name.mappings.properties.data_stream.properties.namespace.type: "constant_keyword" }
383388
- match: { .$idx0name.mappings.properties.data_stream.properties.type.type: "constant_keyword" }
389+
# not one of the three data_stream fields that are explicitly mapped to constant_keyword
390+
- match: { .$idx0name.mappings.properties.data_stream.properties.custom.type: "keyword" }
384391
- match: { .$idx0name.mappings.properties.structured_data.type: "flattened" }
385392
- match: { .$idx0name.mappings.properties.exports.type: "flattened" }
386393
- match: { .$idx0name.mappings.properties.top_level_imports.type: "flattened" }

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1841,7 +1841,6 @@ protected static boolean isXPackTemplate(String name) {
18411841
case "data-streams-mappings":
18421842
case "ecs-dynamic-mappings":
18431843
case "ecs-data-stream-mappings":
1844-
case "string-to-keyword-dynamic-mapping":
18451844
return true;
18461845
default:
18471846
return false;

x-pack/plugin/core/src/main/resources/ecs-data-stream-mappings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"mapping": {
88
"type": "constant_keyword"
99
},
10-
"path_match": "data_stream.*"
10+
"path_match": [
11+
"data_stream.dataset",
12+
"data_stream.namespace",
13+
"data_stream.type"
14+
]
1115
}
1216
}
1317
]

x-pack/plugin/core/src/main/resources/ecs-dynamic-mappings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@
176176
"*imports"
177177
]
178178
}
179+
},
180+
{
181+
"all_strings_to_keywords": {
182+
"mapping": {
183+
"ignore_above": 1024,
184+
"type": "keyword"
185+
},
186+
"match_mapping_type": "string"
187+
}
179188
}
180189
]
181190
}

x-pack/plugin/core/src/main/resources/logs-template.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"data_stream": {},
55
"composed_of": [
66
"logs-mappings",
7-
"ecs-dynamic-mappings",
87
"ecs-data-stream-mappings",
98
"logs-settings",
109
"logs@custom",
11-
"string-to-keyword-dynamic-mapping"
10+
"ecs-dynamic-mappings"
1211
],
1312
"ignore_missing_component_templates": ["logs@custom"],
1413
"allow_auto_create": true,

x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ public class StackTemplateRegistry extends IndexTemplateRegistry {
6060
// ECS dynamic mappings for the data_stream fields
6161
public static final String ECS_DATA_STREAM_MAPPINGS_COMPONENT_TEMPLATE_NAME = "ecs-data-stream-mappings";
6262

63-
// Default mapping of input string fields to keyword
64-
public static final String STRING_TO_KEYWORD_DYNAMIC_TEMPLATE_NAME = "string-to-keyword-dynamic-mapping";
65-
6663
//////////////////////////////////////////////////////////
6764
// Built in ILM policies for users to use
6865
//////////////////////////////////////////////////////////
@@ -176,12 +173,6 @@ protected List<LifecyclePolicy> getPolicyConfigs() {
176173
REGISTRY_VERSION,
177174
TEMPLATE_VERSION_VARIABLE
178175
),
179-
new IndexTemplateConfig(
180-
STRING_TO_KEYWORD_DYNAMIC_TEMPLATE_NAME,
181-
"/string-to-keyword-dynamic-mapping.json",
182-
REGISTRY_VERSION,
183-
TEMPLATE_VERSION_VARIABLE
184-
),
185176
new IndexTemplateConfig(
186177
LOGS_SETTINGS_COMPONENT_TEMPLATE_NAME,
187178
"/logs-settings.json",

x-pack/plugin/stack/src/test/java/org/elasticsearch/xpack/stack/StackTemplateRegistryTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ public void testSameOrHigherVersionTemplateNotUpgraded() {
373373
versions.put(StackTemplateRegistry.DATA_STREAMS_MAPPINGS_COMPONENT_TEMPLATE_NAME, StackTemplateRegistry.REGISTRY_VERSION);
374374
versions.put(StackTemplateRegistry.ECS_DYNAMIC_MAPPINGS_COMPONENT_TEMPLATE_NAME, StackTemplateRegistry.REGISTRY_VERSION);
375375
versions.put(StackTemplateRegistry.ECS_DATA_STREAM_MAPPINGS_COMPONENT_TEMPLATE_NAME, StackTemplateRegistry.REGISTRY_VERSION);
376-
versions.put(StackTemplateRegistry.STRING_TO_KEYWORD_DYNAMIC_TEMPLATE_NAME, StackTemplateRegistry.REGISTRY_VERSION);
377376
versions.put(StackTemplateRegistry.LOGS_SETTINGS_COMPONENT_TEMPLATE_NAME, StackTemplateRegistry.REGISTRY_VERSION);
378377
versions.put(StackTemplateRegistry.LOGS_MAPPINGS_COMPONENT_TEMPLATE_NAME, StackTemplateRegistry.REGISTRY_VERSION);
379378
versions.put(StackTemplateRegistry.METRICS_SETTINGS_COMPONENT_TEMPLATE_NAME, StackTemplateRegistry.REGISTRY_VERSION);
@@ -411,10 +410,6 @@ public void testSameOrHigherVersionTemplateNotUpgraded() {
411410
StackTemplateRegistry.ECS_DATA_STREAM_MAPPINGS_COMPONENT_TEMPLATE_NAME,
412411
StackTemplateRegistry.REGISTRY_VERSION + randomIntBetween(1, 1000)
413412
);
414-
versions.put(
415-
StackTemplateRegistry.STRING_TO_KEYWORD_DYNAMIC_TEMPLATE_NAME,
416-
StackTemplateRegistry.REGISTRY_VERSION + randomIntBetween(1, 1000)
417-
);
418413
versions.put(
419414
StackTemplateRegistry.LOGS_SETTINGS_COMPONENT_TEMPLATE_NAME,
420415
StackTemplateRegistry.REGISTRY_VERSION + randomIntBetween(1, 1000)

0 commit comments

Comments
 (0)