Skip to content

Commit 3e2af4e

Browse files
authored
Map start_timestamp as date rather than date_nanos (#134350)
A nano precision for the start_timestamp is not necessary. For the `@timestamp` field we're also using date, so this is more consistent with that. As ES|QL supports auto-casting now, this change should be safe. We also don't expect real-world queries to use this field, yet. In the future, we might use it internally to detect resets.
1 parent f0e4ee6 commit 3e2af4e

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/30_logsdb_default_mapping.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,3 +1143,101 @@ create logsdb data stream with custom sorting on timestamp:
11431143
index: $backing_index
11441144

11451145
- match: { [email protected]: date }
1146+
1147+
---
1148+
create logsdb data stream with timestamp mixed date_nanos and date fields:
1149+
- requires:
1150+
test_runner_features: [ "allowed_warnings" ]
1151+
1152+
- do:
1153+
cluster.put_component_template:
1154+
name: "logsdb-mappings"
1155+
body:
1156+
template:
1157+
settings:
1158+
mode: "logsdb"
1159+
mappings:
1160+
properties:
1161+
host.name:
1162+
type: "keyword"
1163+
"@timestamp":
1164+
type: "date"
1165+
1166+
- do:
1167+
indices.put_index_template:
1168+
name: "logsdb-index-template"
1169+
body:
1170+
index_patterns: ["logsdb"]
1171+
data_stream: {}
1172+
composed_of: ["logsdb-mappings"]
1173+
allowed_warnings:
1174+
- "index template [logsdb-index-template] has index patterns [logsdb] matching patterns from existing older templates [global] with patterns (global => [*]); this template [logsdb-index-template] will take precedence during new index creation"
1175+
1176+
- do:
1177+
indices.create_data_stream:
1178+
name: "logsdb"
1179+
1180+
- is_true: acknowledged
1181+
- do:
1182+
bulk:
1183+
index: logsdb
1184+
refresh: true
1185+
body:
1186+
- create: {}
1187+
- "@timestamp": 2025-09-09T14:00:00Z
1188+
host.name: localhost
1189+
- is_false: errors
1190+
1191+
- do:
1192+
cluster.put_component_template:
1193+
name: "logsdb-mappings"
1194+
body:
1195+
template:
1196+
settings:
1197+
mode: "logsdb"
1198+
mappings:
1199+
properties:
1200+
host.name:
1201+
type: "keyword"
1202+
"@timestamp":
1203+
type: "date_nanos"
1204+
- do:
1205+
indices.rollover:
1206+
alias: logsdb
1207+
wait_for_active_shards: 1
1208+
- match: { rolled_over: true }
1209+
- do:
1210+
bulk:
1211+
index: logsdb
1212+
refresh: true
1213+
body:
1214+
- create: {}
1215+
- "@timestamp": 2025-09-09T14:00:01Z
1216+
host.name: localhost
1217+
- is_false: errors
1218+
- do:
1219+
search:
1220+
index: logsdb
1221+
body:
1222+
query:
1223+
range:
1224+
"@timestamp":
1225+
gte: "2025-09-09"
1226+
aggs:
1227+
timestamp_histo:
1228+
date_histogram:
1229+
field: "@timestamp"
1230+
calendar_interval: "day"
1231+
- length: { hits.hits: 2 }
1232+
- length: { aggregations.timestamp_histo.buckets: 1 }
1233+
- match: { aggregations.timestamp_histo.buckets.0.key_as_string: "2025-09-09T00:00:00.000Z" }
1234+
- do:
1235+
esql.query:
1236+
body:
1237+
query: 'FROM logsdb | WHERE @timestamp >= "2025-09-09" | STATS min = min(@timestamp) BY day = BUCKET(@timestamp, 1 day) | LIMIT 10'
1238+
- match: { columns.0.name: "min" }
1239+
- match: { columns.0.type: "date_nanos" }
1240+
- match: { columns.1.name: "day" }
1241+
- match: { columns.1.type: "date_nanos" }
1242+
- length: { values: 1 }
1243+
- match: { values.0: [ "2025-09-09T14:00:00.000Z", "2025-09-09T00:00:00.000Z" ] }

x-pack/plugin/otel-data/src/main/resources/component-templates/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ template:
99
mappings:
1010
properties:
1111
start_timestamp:
12-
type: date_nanos
12+
type: date
1313
metrics:
1414
type: passthrough
1515
dynamic: true

x-pack/plugin/otel-data/src/main/resources/resources.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# "version" holds the version of the templates and ingest pipelines installed
22
# by xpack-plugin otel-data. This must be increased whenever an existing template is
33
# changed, in order for it to be updated on Elasticsearch upgrade.
4-
version: 11
4+
version: 12
55

66
component-templates:
77
- otel@mappings

0 commit comments

Comments
 (0)