Module: Fluent::ElasticsearchIndexTemplate
- Included in:
- ElasticsearchOutput
- Defined in:
- lib/fluent/plugin/elasticsearch_index_template.rb
Instance Method Summary collapse
- #get_template(template_file) ⇒ Object
- #template_exists?(name) ⇒ Boolean
- #template_install(name, template_file, overwrite) ⇒ Object
- #template_put(name, template) ⇒ Object
- #templates_hash_install(templates, overwrite) ⇒ Object
Instance Method Details
#get_template(template_file) ⇒ Object
3 4 5 6 7 8 9 |
# 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) ⇒ Boolean
11 12 13 14 15 16 |
# 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, overwrite) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fluent/plugin/elasticsearch_index_template.rb', line 22 def template_install(name, template_file, overwrite) if overwrite template_put(name, get_template(template_file)) log.info("Template '#{name}' overwritten with #{template_file}.") return end 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) ⇒ Object
18 19 20 |
# 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, overwrite) ⇒ Object
36 37 38 39 40 |
# File 'lib/fluent/plugin/elasticsearch_index_template.rb', line 36 def templates_hash_install(templates, overwrite) templates.each do |key, value| template_install(key, value, overwrite) end end |