Class: Elastomer::Client::Warmer

Inherits:
Object
  • Object
show all
Defined in:
lib/elastomer/client/warmer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, index_name, name) ⇒ Warmer

Create a new Warmer helper for making warmer API requests.

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



22
23
24
25
26
# File 'lib/elastomer/client/warmer.rb', line 22

def initialize(client, index_name, name)
  @client     = client
  @index_name = @client.assert_param_presence(index_name, 'index name')
  @name       = @client.assert_param_presence(name, 'warmer name')
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



28
29
30
# File 'lib/elastomer/client/warmer.rb', line 28

def client
  @client
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



28
29
30
# File 'lib/elastomer/client/warmer.rb', line 28

def index_name
  @index_name
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/elastomer/client/warmer.rb', line 28

def name
  @name
end

Instance Method Details

#create(query, params = {}) ⇒ Object

Create a warmer. See www.elasticsearch.org/guide/reference/api/admin-indices-warmers/

query - The query the warmer should run params - Parameters Hash

Examples

warmer.create(:query => {:match_all => {}})

Returns the response body as a Hash



41
42
43
44
# File 'lib/elastomer/client/warmer.rb', line 41

def create(query, params = {})
  response = client.put '/{index}{/type}/_warmer/{warmer}', defaults.update(params.update(:body => query))
  response.body
end

#defaultsObject

Internal: Returns a Hash containing default parameters.



91
92
93
# File 'lib/elastomer/client/warmer.rb', line 91

def defaults
  {:index => index_name, :warmer => name}
end

#delete(params = {}) ⇒ Object

Delete a warmer. See www.elasticsearch.org/guide/reference/api/admin-indices-warmers/

params - Parameters Hash

Returns the response body as a Hash



52
53
54
55
# File 'lib/elastomer/client/warmer.rb', line 52

def delete(params = {})
  response = client.delete '/{index}{/type}/_warmer/{warmer}', defaults.update(params)
  response.body
end

#exists?Boolean Also known as: exist?

Check whether a warmer exists. Also aliased as exist?

Since there is no native warmer exists api, this method executes a get and watches for an IndexWarmerMissingException error.

Returns true if the warmer exists, false if not. COMPATIBILITY warmer response differs in ES 1.0 ES 1.0: missing warmer returns {} with 200 status ES 0.90: missing warmer returns IndexWarmerMissingException error See github.com/elasticsearch/elasticsearch/issues/5155

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
87
# File 'lib/elastomer/client/warmer.rb', line 78

def exists?
  response = get
  response != {}
rescue Elastomer::Client::Error => exception
  if exception.message =~ /IndexWarmerMissingException/
    false
  else
    raise exception
  end
end

#get(params = {}) ⇒ Object

Get a warmer. See www.elasticsearch.org/guide/reference/api/admin-indices-warmers/

params - Parameters Hash

Returns the response body as a Hash



63
64
65
66
# File 'lib/elastomer/client/warmer.rb', line 63

def get(params = {})
  response = client.get '/{index}{/type}/_warmer/{warmer}', defaults.update(params)
  response.body
end