Class: ElasticSearch::Index
- Inherits:
-
Object
- Object
- ElasticSearch::Index
- Defined in:
- lib/elastic_search/index.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.
Instance Method Summary collapse
- #close ⇒ Object
- #execute(request) ⇒ Object
- #exists? ⇒ Boolean
- #get_type(type_name) ⇒ Object (also: #[])
-
#initialize(index_name, client) ⇒ Index
constructor
A new instance of Index.
- #mapping ⇒ Object
- #mapping=(mapping) ⇒ Object
- #open ⇒ Object
- #optimize(options = {}) ⇒ Object
- #refresh ⇒ Object
- #search(body, parameters = {}) ⇒ Object
- #settings ⇒ Object
- #settings=(settings) ⇒ Object
Constructor Details
#initialize(index_name, client) ⇒ Index
Returns a new instance of Index.
5 6 7 8 9 |
# File 'lib/elastic_search/index.rb', line 5 def initialize(index_name, client) @index_name = index_name @client = client @types = {} end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/elastic_search/index.rb', line 3 def client @client end |
#index_name ⇒ Object (readonly)
Returns the value of attribute index_name.
3 4 5 |
# File 'lib/elastic_search/index.rb', line 3 def index_name @index_name end |
Instance Method Details
#close ⇒ Object
32 33 34 35 |
# File 'lib/elastic_search/index.rb', line 32 def close request = build_request(method: :post, action: :close) execute(request) end |
#execute(request) ⇒ Object
66 67 68 |
# File 'lib/elastic_search/index.rb', line 66 def execute(request) @client.execute(request) end |
#exists? ⇒ Boolean
62 63 64 |
# File 'lib/elastic_search/index.rb', line 62 def exists? @client.has_index?(@index_name) end |
#get_type(type_name) ⇒ Object Also known as: []
11 12 13 |
# File 'lib/elastic_search/index.rb', line 11 def get_type(type_name) @types[type_name.to_sym] ||= ElasticSearch::Type.new(type_name, self) end |
#mapping ⇒ Object
47 48 49 50 |
# File 'lib/elastic_search/index.rb', line 47 def mapping request = build_request(method: :get, action: :mapping) execute(request).body end |
#mapping=(mapping) ⇒ Object
52 53 54 55 |
# File 'lib/elastic_search/index.rb', line 52 def mapping=(mapping) request = build_request(method: :put, action: :mapping, body: mapping) execute(request).status.eql?(200) end |
#open ⇒ Object
27 28 29 30 |
# File 'lib/elastic_search/index.rb', line 27 def open request = build_request(method: :post, action: :open) execute(request) end |
#optimize(options = {}) ⇒ Object
57 58 59 60 |
# File 'lib/elastic_search/index.rb', line 57 def optimize( = {}) request = build_request(method: :post, action: :optimize, parameters: ) execute(request).status.eql?(200) end |
#refresh ⇒ Object
22 23 24 25 |
# File 'lib/elastic_search/index.rb', line 22 def refresh request = build_request(method: :post, action: :refresh) execute(request) end |
#search(body, parameters = {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/elastic_search/index.rb', line 16 def search(body, parameters = {}) request = build_request(method: :get, action: :search, parameters: parameters, body: body || {}) response = execute(request) ElasticSearch::Search::Results.new(response) end |
#settings ⇒ Object
37 38 39 40 |
# File 'lib/elastic_search/index.rb', line 37 def settings request = build_request(method: :get, action: :settings) execute(request).body end |
#settings=(settings) ⇒ Object
42 43 44 45 |
# File 'lib/elastic_search/index.rb', line 42 def settings=(settings) request = build_request(method: :put, action: :settings, body: settings) execute(request) end |