Skip to content

Commit 1bb2161

Browse files
committed
make template required when template_api is provided
1 parent 6038383 commit 1bb2161

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

docs/index.asciidoc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,25 +1077,22 @@ the *$JDK_HOME/conf/security/java.security* configuration file. That is, `TLSv1.
10771077

10781078
* Value type is <<path,path>>
10791079
* There is no default value for this setting.
1080+
* When a `template` is provided, you may also configure <<plugins-{type}s-{plugin}-template_api>> as a hint about the format of the provided template.
10801081

10811082
You can set the path to your own template here, if you so desire.
10821083
If not set, the included template will be used.
10831084

10841085
[id="plugins-{type}s-{plugin}-template_api"]
10851086
===== `template_api`
10861087

1087-
* Value can be any of: `auto`, `legacy`, `composable`
1088-
* Default value is `auto`
1089-
1090-
The default setting of `auto` will use
1091-
{ref}/index-templates.html[index template API] to create index template, if the
1092-
Elasticsearch cluster is running Elasticsearch version `8.0.0` or higher,
1093-
and use {ref}/indices-templates-v1.html[legacy template API] otherwise.
1094-
1095-
Setting this flag to `legacy` will use legacy template API to create index template.
1096-
Setting this flag to `composable` will use index template API to create index template.
1088+
* Value can be any of:
1089+
** `composable`: maps to composable {ref}/index-templates.html[index template API]
1090+
** `legacy`: maps to the {ref}/indices-templates-v1.html[legacy template API]
1091+
* The default value is determined based on which version of Elasticsearch we are connected to:
1092+
** for {es} 7.x or older, the default is `legacy`
1093+
** for {es} 8.0+, the default is `composable`
10971094

1098-
NOTE: The format of template provided to <<plugins-{type}s-{plugin}-template>> needs to match the template API being used.
1095+
This is a hint for the format of the provided <<plugins-{type}s-{plugin}-template>>.
10991096

11001097
[id="plugins-{type}s-{plugin}-template_name"]
11011098
===== `template_name`

lib/logstash/outputs/elasticsearch.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
279279
def initialize(*params)
280280
super
281281
setup_ecs_compatibility_related_defaults
282+
283+
raise LogStash::ConfigurationError("`template_api` is not allowed unless a `template` is also provided") if original_params.include?('template_api') && !original_params.include?('template')
282284
end
283285

284286
def register

lib/logstash/outputs/elasticsearch/template_manager.rb

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ class TemplateManager
77
def self.install_template(plugin)
88
return unless plugin.manage_template
99

10-
if plugin.maximum_seen_major_version < 8 && plugin.template_api == 'auto'
11-
plugin.logger.warn("`template_api => auto` resolved to `legacy` since we are connected to " + "Elasticsearch #{plugin.maximum_seen_major_version}, " +
12-
"but will resolve to `composable` the first time it connects to Elasticsearch 8+. " +
13-
"We recommend either setting `template_api => legacy` to continue providing legacy-style templates, " +
14-
"or migrating your template to the composable style and setting `template_api => composable`. " +
15-
"The legacy template API is slated for removal in Elasticsearch 9.")
16-
end
17-
1810
if plugin.template
11+
if plugin.maximum_seen_major_version < 8 && plugin.template_api == 'auto'
12+
plugin.logger.warn("`template_api => auto` resolved to `legacy` since we are connected to " + "Elasticsearch #{plugin.maximum_seen_major_version}, " +
13+
"but will resolve to `composable` the first time it connects to Elasticsearch 8+. " +
14+
"We recommend either setting `template_api => legacy` to continue providing legacy-style templates, " +
15+
"or migrating your template to the composable style and setting `template_api => composable`. " +
16+
"The legacy template API is slated for removal in Elasticsearch 9.")
17+
end
18+
1919
plugin.logger.info("Using mapping template from", :path => plugin.template)
2020
template = read_template_file(plugin.template)
2121
else
@@ -82,12 +82,11 @@ def self.read_template_file(template_path)
8282
end
8383

8484
def self.template_endpoint(plugin)
85-
if plugin.template_api == 'auto'
86-
plugin.maximum_seen_major_version < 8 ? LEGACY_TEMPLATE_ENDPOINT : INDEX_TEMPLATE_ENDPOINT
87-
elsif plugin.template_api.to_s == 'legacy'
88-
LEGACY_TEMPLATE_ENDPOINT
85+
case plugin.template_api.to_s
86+
when 'composable' then INDEX_TEMPLATE_ENDPOINT
87+
when 'legacy' then LEGACY_TEMPLATE_ENDPOINT
8988
else
90-
INDEX_TEMPLATE_ENDPOINT
89+
plugin.maximum_seen_major_version < 8 ? LEGACY_TEMPLATE_ENDPOINT : INDEX_TEMPLATE_ENDPOINT
9190
end
9291
end
9392

0 commit comments

Comments
 (0)