Skip to content

Commit

Permalink
Always show composed_of field for composable index templates
Browse files Browse the repository at this point in the history
Prior to e786cfa we inadvertently always added composable index
templates with `composed_of: []` beacuse
elastic@e786cfa#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 elastic#104627
  • Loading branch information
dakrone committed Feb 8, 2024
1 parent 97dbb2a commit 02ea48c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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: []}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.xcontent.XContentParser;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -273,7 +274,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params, @Nulla
builder.field(TEMPLATE.getPreferredName());
this.template.toXContent(builder, params, rolloverConfiguration);
}
if (this.componentTemplates != null) {
if (this.componentTemplates == null) {
builder.stringListField(COMPOSED_OF.getPreferredName(), Collections.emptyList());
} else {
builder.stringListField(COMPOSED_OF.getPreferredName(), this.componentTemplates);
}
if (this.priority != null) {
Expand Down

0 comments on commit 02ea48c

Please sign in to comment.