Class: Elastomer::Client::Warmer
- Inherits:
-
Object
- Object
- Elastomer::Client::Warmer
- Defined in:
- lib/elastomer/client/warmer.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#index_name ⇒ Object
readonly
Returns the value of attribute index_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#create(query, params = {}) ⇒ Object
Create a warmer.
-
#defaults ⇒ Object
Internal: Returns a Hash containing default parameters.
-
#delete(params = {}) ⇒ Object
Delete a warmer.
-
#exists? ⇒ Boolean
(also: #exist?)
Check whether a warmer exists.
-
#get(params = {}) ⇒ Object
Get a warmer.
-
#initialize(client, index_name, name) ⇒ Warmer
constructor
Create a new Warmer helper for making warmer API requests.
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
11 12 13 14 15 |
# File 'lib/elastomer/client/warmer.rb', line 11 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
#client ⇒ Object (readonly)
Returns the value of attribute client.
17 18 19 |
# File 'lib/elastomer/client/warmer.rb', line 17 def client @client end |
#index_name ⇒ Object (readonly)
Returns the value of attribute index_name.
17 18 19 |
# File 'lib/elastomer/client/warmer.rb', line 17 def index_name @index_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/elastomer/client/warmer.rb', line 17 def name @name end |
Instance Method Details
#create(query, params = {}) ⇒ Object
Create a warmer. See www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html
query - The query the warmer should run params - Parameters Hash
Examples
warmer.create(:query => {:match_all => {}})
Returns the response body as a Hash
30 31 32 33 |
# File 'lib/elastomer/client/warmer.rb', line 30 def create(query, params = {}) response = client.put "/{index}{/type}/_warmer/{warmer}", defaults.update(params.update(:body => query)) response.body end |
#defaults ⇒ Object
Internal: Returns a Hash containing default parameters.
80 81 82 |
# File 'lib/elastomer/client/warmer.rb', line 80 def defaults {:index => index_name, :warmer => name} end |
#delete(params = {}) ⇒ Object
Delete a warmer. See www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html#removing
params - Parameters Hash
Returns the response body as a Hash
41 42 43 44 |
# File 'lib/elastomer/client/warmer.rb', line 41 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
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/elastomer/client/warmer.rb', line 67 def exists? response = get response != {} rescue Elastomer::Client::Error => exception if exception. =~ /IndexWarmerMissingException/ false else raise exception end end |
#get(params = {}) ⇒ Object
Get a warmer. See www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html#warmer-retrieving
params - Parameters Hash
Returns the response body as a Hash
52 53 54 55 |
# File 'lib/elastomer/client/warmer.rb', line 52 def get(params = {}) response = client.get "/{index}{/type}/_warmer/{warmer}", defaults.update(params) response.body end |