Class: Elastomer::Client::Percolator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, index_name, id) ⇒ Percolator

Create a new Percolator for managing a query.

client - Elastomer::Client used for HTTP requests to the server index_name - The index name id - The _id for the query



11
12
13
14
15
16
17
18
# File 'lib/elastomer/client/percolator.rb', line 11

def initialize(client, index_name, id)
  @client = client
  @index_name = client.assert_param_presence(index_name, "index name")
  @id = client.assert_param_presence(id, "id")

  # COMPATIBILITY
  @percolator_type = client.version_support.percolator_type
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/elastomer/client/percolator.rb', line 20

def client
  @client
end

#idObject (readonly)

Returns the value of attribute id.



20
21
22
# File 'lib/elastomer/client/percolator.rb', line 20

def id
  @id
end

#index_nameObject (readonly)

Returns the value of attribute index_name.



20
21
22
# File 'lib/elastomer/client/percolator.rb', line 20

def index_name
  @index_name
end

Instance Method Details

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

Create a percolator query.

Examples

percolator = $client.index("default-index").percolator "1"
percolator.create query: { match_all: { } }

Returns the response body as a Hash



30
31
32
33
# File 'lib/elastomer/client/percolator.rb', line 30

def create(body, params = {})
  response = client.put("/{index}/#{@percolator_type}/{id}", defaults.merge(params.merge(body: body, action: "percolator.create")))
  response.body
end

#defaultsObject

Internal: Returns a Hash containing default parameters.



74
75
76
# File 'lib/elastomer/client/percolator.rb', line 74

def defaults
  {index: index_name, id: id}
end

#delete(params = {}) ⇒ Object

Delete a percolator query.

Examples

percolator = $client.index("default-index").percolator "1"
percolator.delete

Returns the response body as a Hash



56
57
58
59
# File 'lib/elastomer/client/percolator.rb', line 56

def delete(params = {})
  response = client.delete("/{index}/#{@percolator_type}/{id}", defaults.merge(params.merge(action: "percolator.delete")))
  response.body
end

#exists?(params = {}) ⇒ Boolean

Checks for the existence of a percolator query.

Examples

percolator = $client.index("default-index").percolator "1"
percolator.exists?

Returns a boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/elastomer/client/percolator.rb', line 69

def exists?(params = {})
  get(params)["found"]
end

#get(params = {}) ⇒ Object

Gets a percolator query.

Examples

percolator = $client.index("default-index").percolator "1"
percolator.get

Returns the response body as a Hash



43
44
45
46
# File 'lib/elastomer/client/percolator.rb', line 43

def get(params = {})
  response = client.get("/{index}/#{@percolator_type}/{id}", defaults.merge(params.merge(action: "percolator.get")))
  response.body
end