From 009a847273a48633e735c8934c6c994f0e9877f3 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 15 Feb 2024 11:23:19 -0700 Subject: [PATCH] Always show `composed_of` field for composable index templates (#105315) * Always show `composed_of` field for composable index templates Prior to e786cfa7061b427cf6185ad907069838dd679574 we inadvertently always added composable index templates with `composed_of: []` beacuse https://github.com/elastic/elasticsearch/commit/e786cfa7061b427cf6185ad907069838dd679574#diff-5081302eb39033199deb1977d544d1cd7867212a92b8d77e0aa0ded361272b11L618-L630 created a new `ComposableIndexTemplate` from an existing one, and the `.composedOf()` field returned an empty list of no component templates were provided: https://github.com/elastic/elasticsearch/blob/89e714ee5dc60db8b4979ab6372ff767e108e9da/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplate.java#L172-L177 This meant that before 8.12.0 we would always show `composed_of: []` for composable index templates. This commit recreates this behavior, and always displays the empty list even if no component templates are used by a composable index template. Resolves #104627 --- docs/changelog/105315.yaml | 6 ++++++ .../test/indices.get_index_template/10_basic.yml | 13 +++++++++++++ .../cluster/metadata/ComposableIndexTemplate.java | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/105315.yaml diff --git a/docs/changelog/105315.yaml b/docs/changelog/105315.yaml new file mode 100644 index 0000000000000..207e72467a689 --- /dev/null +++ b/docs/changelog/105315.yaml @@ -0,0 +1,6 @@ +pr: 105315 +summary: Always show `composed_of` field for composable index templates +area: Indices APIs +type: bug +issues: + - 104627 diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_index_template/10_basic.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_index_template/10_basic.yml index 41e5506c412cd..fcf4a75af2227 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_index_template/10_basic.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_index_template/10_basic.yml @@ -188,3 +188,16 @@ setup: type: keyword lifecycle: data_retention: "30d" + +--- +"Get index template always shows composed_of": + - skip: + version: " - 8.12.99" + reason: "A bug was fixed in 8.13.0 to make `composed_of` always returned" + + - do: + indices.get_index_template: + name: test + + - match: {index_templates.0.name: test} + - match: {index_templates.0.index_template.composed_of: []} diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplate.java b/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplate.java index dfd4431eb073c..7702ec0ac0b5c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplate.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/ComposableIndexTemplate.java @@ -125,7 +125,7 @@ private ComposableIndexTemplate( ) { this.indexPatterns = indexPatterns; this.template = template; - this.componentTemplates = componentTemplates; + this.componentTemplates = componentTemplates == null ? List.of() : componentTemplates; this.priority = priority; this.version = version; this.metadata = metadata;