Class: LogStash::Outputs::ElasticSearch::TemplateManager

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/elasticsearch/template_manager.rb

Constant Summary collapse

LEGACY_TEMPLATE_ENDPOINT =
'_template'.freeze
INDEX_TEMPLATE_ENDPOINT =
'_index_template'.freeze

Class Method Summary collapse

Class Method Details

.install_template(plugin) ⇒ Object

To be mixed into the elasticsearch plugin base



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/logstash/outputs/elasticsearch/template_manager.rb', line 7

def self.install_template(plugin)
  return unless plugin.manage_template

  if plugin.maximum_seen_major_version < 8 && plugin.template_api == 'auto'
    plugin.logger.warn("`template_api => auto` resolved to `legacy` since we are connected to " + "Elasticsearch #{plugin.maximum_seen_major_version}, " +
                       "but will resolve to `composable` the first time it connects to Elasticsearch 8+. " +
                       "We recommend either setting `template_api => legacy` to continue providing legacy-style templates, " +
                       "or migrating your template to the composable style and setting `template_api => composable`. " +
                       "The legacy template API is slated for removal in Elasticsearch 9.")
  elsif plugin.template_api == 'legacy' && plugin.serverless?
    raise LogStash::ConfigurationError, "Invalid template configuration `template_api => legacy`. Serverless Elasticsearch does not support legacy template API."
  end


  if plugin.template
    plugin.logger.info("Using mapping template from", :path => plugin.template)
    template = read_template_file(plugin.template)
  else
    plugin.logger.info("Using a default mapping template", :es_version => plugin.maximum_seen_major_version,
                                                           :ecs_compatibility => plugin.ecs_compatibility)
    template = load_default_template(plugin.maximum_seen_major_version, plugin.ecs_compatibility)
  end

  add_ilm_settings_to_template(plugin, template) if plugin.ilm_in_use?
  plugin.logger.debug("Attempting to install template", template: template)
  install(plugin.client, template_endpoint(plugin), template_name(plugin), template, plugin.template_overwrite)
end