Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions docs/changelog/137852.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 137852
summary: Fixing get data stream API when data stream index mode has been changed
to `time_series`
area: Data streams
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,267 @@
- match: { data_streams.0.effective_mappings: null }
- set: { data_streams.0.indices.0.index_name: oldIndexName }
- set: { data_streams.0.indices.1.index_name: newIndexName }

---
"Test change data stream from standard to time_series with no routing_path":
# This test makes sure that if we change the index mode of a data stream from standard to time_series without a
# configured routing_path, the get data stream and get data stream mappings APIs do not blow up before or after
# rollover.
- do:
indices.put_index_template:
name: my-template
body:
index_patterns: [ test-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
mappings:
properties:
field1:
type: keyword

- do:
indices.create_data_stream:
name: test-data-stream-1

- do:
indices.put_index_template:
name: my-template
body:
index_patterns: [ test-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
mode: time_series
mappings:
properties:
field1:
type: keyword
time_series_dimension: true

- do:
cluster.health:
index: "test-data-stream-1"
wait_for_status: green

- do:
indices.get_data_stream_mappings:
name: test-data-stream-1
- match: { data_streams.0.name: test-data-stream-1 }
- match: { data_streams.0.mappings: {} }
- length: { data_streams.0.effective_mappings.properties: 2 }

- do:
indices.get_data_stream:
name: test-data-stream-1
- match: { data_streams.0.name: test-data-stream-1 }
- match: { data_streams.0.mappings: {} }
- match: { data_streams.0.effective_mappings: null }

- do:
indices.rollover:
alias: "test-data-stream-1"

- do:
cluster.health:
index: "test-data-stream-1"
wait_for_status: green

- do:
indices.get_data_stream_mappings:
name: test-data-stream-1
- match: { data_streams.0.name: test-data-stream-1 }
- length: { data_streams.0.effective_mappings.properties: 2 }
- match: { data_streams.0.effective_mappings.properties.field1.type: "keyword" }

- do:
indices.get_data_stream:
name: test-data-stream-1
- match: { data_streams.0.name: test-data-stream-1 }
- match: { data_streams.0.mappings: { } }
- match: { data_streams.0.effective_mappings: null }
- set: { data_streams.0.indices.0.index_name: oldIndexName }
- set: { data_streams.0.indices.1.index_name: newIndexName }

---
"Test change data stream from time_series to standard with no routing_path":
# This test makes sure that if we change the index mode of a data stream from time_series without a configured
# routing_path to standard, the get data stream and get data stream mappings APIs do not blow up before or after
# rollover.
- do:
indices.put_index_template:
name: my-template
body:
index_patterns: [ my-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
mode: time_series
mappings:
properties:
field1:
type: keyword
time_series_dimension: true

- do:
indices.create_data_stream:
name: my-data-stream-1

- do:
cluster.health:
index: "my-data-stream-1"
wait_for_status: green

- do:
indices.get_data_stream_mappings:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.mappings: {} }
- length: { data_streams.0.effective_mappings.properties: 2 }

- do:
indices.get_data_stream:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.mappings: {} }
- match: { data_streams.0.effective_mappings: null }

- do:
indices.put_index_template:
name: my-template
body:
index_patterns: [ my-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
mappings:
properties:
field1:
type: keyword

- do:
indices.get_data_stream_mappings:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.mappings: {} }
- length: { data_streams.0.effective_mappings.properties: 2 }

- do:
indices.get_data_stream:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.mappings: {} }
- match: { data_streams.0.effective_mappings: null }

- do:
indices.rollover:
alias: "my-data-stream-1"

- do:
cluster.health:
index: "my-data-stream-1"
wait_for_status: green

- do:
indices.get_data_stream_mappings:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- length: { data_streams.0.effective_mappings.properties: 2 }
- match: { data_streams.0.effective_mappings.properties.field1.type: "keyword" }

- do:
indices.get_data_stream:
name: my-data-stream-1
- match: { data_streams.0.name: my-data-stream-1 }
- match: { data_streams.0.mappings: { } }
- match: { data_streams.0.effective_mappings: null }
- set: { data_streams.0.indices.0.index_name: oldIndexName }
- set: { data_streams.0.indices.1.index_name: newIndexName }

---
"Test change data stream from standard to time_series with routing_path":
# This test makes sure that if we change the index mode of a data stream from standard to time_series with a
# configured routing_path, the get data stream and get data stream mappings APIs do not blow up before or after
# rollover.
- do:
indices.put_index_template:
name: my-template
body:
index_patterns: [ test-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
mappings:
properties:
field1:
type: keyword

- do:
indices.create_data_stream:
name: test-data-stream-1

- do:
indices.put_index_template:
name: my-template
body:
index_patterns: [ test-data-stream-* ]
data_stream: { }
template:
settings:
number_of_replicas: 0
routing_path: field1
mode: time_series
mappings:
properties:
field1:
type: keyword
time_series_dimension: true

- do:
cluster.health:
index: "test-data-stream-1"
wait_for_status: green

- do:
indices.get_data_stream_mappings:
name: test-data-stream-1
- match: { data_streams.0.name: test-data-stream-1 }
- match: { data_streams.0.mappings: {} }
- length: { data_streams.0.effective_mappings.properties: 2 }

- do:
indices.get_data_stream:
name: test-data-stream-1
- match: { data_streams.0.name: test-data-stream-1 }
- match: { data_streams.0.mappings: {} }
- match: { data_streams.0.effective_mappings: null }

- do:
indices.rollover:
alias: "test-data-stream-1"

- do:
cluster.health:
index: "test-data-stream-1"
wait_for_status: green

- do:
indices.get_data_stream_mappings:
name: test-data-stream-1
- match: { data_streams.0.name: test-data-stream-1 }
- length: { data_streams.0.effective_mappings.properties: 2 }
- match: { data_streams.0.effective_mappings.properties.field1.type: "keyword" }

- do:
indices.get_data_stream:
name: test-data-stream-1
- match: { data_streams.0.name: test-data-stream-1 }
- match: { data_streams.0.mappings: { } }
- match: { data_streams.0.effective_mappings: null }
- set: { data_streams.0.indices.0.index_name: oldIndexName }
- set: { data_streams.0.indices.1.index_name: newIndexName }
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,23 @@ public static CompressedXContent getEffectiveMappings(
* mapping, we make sure to correct the index mode and index routing path here.
*/
IndexMetadata oldIndexMetadata = indexService.getMetadata();
Settings.Builder settingsBuilder = Settings.builder().put(oldIndexMetadata.getSettings());
settingsBuilder.put(indexModeSettingName, templateSettings.get(indexModeSettingName));

Settings oldIndexSettings = oldIndexMetadata.getSettings();
String indexRoutingPathSettingName = IndexMetadata.INDEX_ROUTING_PATH.getKey();
settingsBuilder.put(indexRoutingPathSettingName, templateSettings.get(indexRoutingPathSettingName));
IndexMetadata newIndexMetadata = new IndexMetadata.Builder(oldIndexMetadata).settings(settingsBuilder.build()).build();
mapperService.getIndexSettings().updateIndexMetadata(newIndexMetadata);
if (Objects.equals(
templateSettings.get(indexRoutingPathSettingName),
oldIndexSettings.get(indexRoutingPathSettingName)
) == false) {
/*
* If the routing_path has changed, we need to make sure to update it so that validation does not fail when we merge
* mappings.
*/
Settings.Builder settingsBuilder = Settings.builder().put(oldIndexSettings);
settingsBuilder.put(indexModeSettingName, templateSettings.get(indexModeSettingName));
settingsBuilder.put(indexRoutingPathSettingName, templateSettings.get(indexRoutingPathSettingName));
IndexMetadata newIndexMetadata = new IndexMetadata.Builder(oldIndexMetadata).settings(settingsBuilder.build()).build();
mapperService.getIndexSettings().updateIndexMetadata(newIndexMetadata);
}
}
CompressedXContent mergedMapping = mapperService.merge(
MapperService.SINGLE_MAPPING_NAME,
Expand Down