Class: Stretcher::EsComponent
- Inherits:
-
Object
- Object
- Stretcher::EsComponent
show all
- Defined in:
- lib/stretcher/es_component.rb
Overview
Elasticsearch has symmetry across API endpoints for Server, Index, and Type, lets try and provide some common ground
Instance Method Summary
collapse
Instance Method Details
#do_alias(alias_name_or_prefix) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/stretcher/es_component.rb', line 40
def do_alias(alias_name_or_prefix)
request(:get, "_alias/#{alias_name_or_prefix}")
rescue Stretcher::RequestError::NotFound => e
return {} if e.http_response.status == 404
raise e
end
|
#do_delete_query(query) ⇒ Object
34
35
36
37
38
|
# File 'lib/stretcher/es_component.rb', line 34
def do_delete_query(query)
request :delete, '_query' do |req|
req.body = query
end
end
|
#do_refresh ⇒ Object
24
25
26
|
# File 'lib/stretcher/es_component.rb', line 24
def do_refresh
request(:post, "_refresh")
end
|
#do_search(generic_opts = {}, explicit_body = nil) ⇒ Object
Many of the methods marked protected are called by one line shims in subclasses. This is mostly to facilitate better looking rdocs
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/stretcher/es_component.rb', line 8
def do_search(generic_opts={}, explicit_body=nil)
query_opts = {}
body = nil
if explicit_body
query_opts = generic_opts
body = explicit_body
else
body = generic_opts
end
response = request(:get, "_search", query_opts) do |req|
req.body = body
end
SearchResults.new(response)
end
|
#request(method, path = nil, params = {}, body = nil, headers = {}, &block) ⇒ Object
28
29
30
31
32
|
# File 'lib/stretcher/es_component.rb', line 28
def request(method, path=nil, params={}, body=nil, ={}, &block)
prefixed_path = path_uri(path)
raise "Cannot issue request, no server specified!" unless @server
@server.request(method, prefixed_path, params, body, , &block)
end
|