module Fluent::ElasticsearchIndexTemplate

Public Instance Methods

get_template(template_file) click to toggle source
# File lib/fluent/plugin/elasticsearch_index_template.rb, line 3
def get_template(template_file)
  if !File.exists?(template_file)
    raise "If you specify a template_name you must specify a valid template file (checked '#{template_file}')!"
  end
  file_contents = IO.read(template_file).gsub(/\n/,'')
  JSON.parse(file_contents)
end
template_exists?(name) click to toggle source
# File lib/fluent/plugin/elasticsearch_index_template.rb, line 11
def template_exists?(name)
  client.indices.get_template(:name => name)
  return true
rescue Elasticsearch::Transport::Transport::Errors::NotFound
  return false
end
template_install(name, template_file) click to toggle source
# File lib/fluent/plugin/elasticsearch_index_template.rb, line 22
def template_install(name, template_file)
  if !template_exists?(name)
    template_put(name, get_template(template_file))
    log.info("Template configured, but no template installed. Installed '#{name}' from #{template_file}.")
  else
    log.info("Template configured and already installed.")
  end
end
template_put(name, template) click to toggle source
# File lib/fluent/plugin/elasticsearch_index_template.rb, line 18
def template_put(name, template)
  client.indices.put_template(:name => name, :body => template)
end
templates_hash_install(templates) click to toggle source
# File lib/fluent/plugin/elasticsearch_index_template.rb, line 31
def templates_hash_install (templates)
  templates.each do |key, value|
    template_install(key, value)
  end
end