class Elastomer::Client::Template

Attributes

client[R]
name[R]

Public Class Methods

new( client, name ) click to toggle source

Create a new template client for making API requests that pertain to template management.

client - Elastomer::Client used for HTTP requests to the server name - The name of the template as a String

# File lib/elastomer/client/template.rb, line 19
def initialize( client, name )
  @client = client
  @name   = name
end

Public Instance Methods

create( template, params = {} ) click to toggle source

Create the template on the cluster. See www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html

template - The template as a Hash or a JSON encoded String params - Parameters Hash

Returns the response body as a Hash

# File lib/elastomer/client/template.rb, line 51
def create( template, params = {} )
  response = client.put "/_template/{template}", update_params(params, body: template, action: "template.create", rest_api: "indices.put_template")
  response.body
end
defaults() click to toggle source

Internal: Returns a Hash containing default parameters.

# File lib/elastomer/client/template.rb, line 81
def defaults
  { template: name }
end
delete( params = {} ) click to toggle source

Delete the template from the cluster. See www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#delete

params - Parameters Hash

Returns the response body as a Hash

# File lib/elastomer/client/template.rb, line 62
def delete( params = {} )
  response = client.delete "/_template/{template}", update_params(params, action: "template.delete", rest_api: "indices.delete_template")
  response.body
end
exist?( params = {} )
Alias for: exists?
exists?( params = {} ) click to toggle source

Returns true if the template already exists on the cluster.

# File lib/elastomer/client/template.rb, line 27
def exists?( params = {} )
  response = client.head "/_template/{template}", update_params(params, action: "template.exists", rest_api: "indices.exists_template")
  response.success?
end
Also aliased as: exist?
get( params = {} ) click to toggle source

Get the template from the cluster. See www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#getting

params - Parameters Hash

Returns the response body as a Hash

# File lib/elastomer/client/template.rb, line 39
def get( params = {} )
  response = client.get "/_template/{template}", update_params(params, action: "template.get", rest_api: "indices.get_template")
  response.body
end
update_params( params, overrides = nil ) click to toggle source

Internal: Add default parameters to the `params` Hash and then apply `overrides` to the params if any are given.

params - Parameters Hash overrides - Optional parameter overrides as a Hash

Returns a new params Hash.

# File lib/elastomer/client/template.rb, line 74
def update_params( params, overrides = nil )
  h = defaults.update params
  h.update overrides unless overrides.nil?
  h
end