Class: Elasticsearch::Extensions::Documents::Storage
- Inherits:
-
Object
- Object
- Elasticsearch::Extensions::Documents::Storage
- Defined in:
- lib/elasticsearch/extensions/documents/storage.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #create_index(index_name) ⇒ Object
- #drop_index(index_name) ⇒ Object
- #index_definition ⇒ Object
- #index_exists?(index_name) ⇒ Boolean
-
#initialize(options = {}) ⇒ Storage
constructor
A new instance of Storage.
Constructor Details
#initialize(options = {}) ⇒ Storage
Returns a new instance of Storage.
8 9 10 11 |
# File 'lib/elasticsearch/extensions/documents/storage.rb', line 8 def initialize( = {}) @client = .fetch(:client) { Documents.client } @config = .fetch(:config) { Documents.configuration } end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/elasticsearch/extensions/documents/storage.rb', line 6 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/elasticsearch/extensions/documents/storage.rb', line 6 def config @config end |
Instance Method Details
#create_index(index_name) ⇒ Object
21 22 23 |
# File 'lib/elasticsearch/extensions/documents/storage.rb', line 21 def create_index(index_name) client.indices.create(index: index_name, body: index_definition) unless index_exists?(index_name) end |
#drop_index(index_name) ⇒ Object
13 14 15 |
# File 'lib/elasticsearch/extensions/documents/storage.rb', line 13 def drop_index(index_name) client.indices.delete(index: index_name) if index_exists?(index_name) end |
#index_definition ⇒ Object
25 26 27 28 29 30 |
# File 'lib/elasticsearch/extensions/documents/storage.rb', line 25 def index_definition {}.tap do |body| body[:settings] = config.settings if config.settings body[:mappings] = config.mappings if config.mappings end end |
#index_exists?(index_name) ⇒ Boolean
17 18 19 |
# File 'lib/elasticsearch/extensions/documents/storage.rb', line 17 def index_exists?(index_name) client.indices.exists(index: index_name) end |