Module: Elasticsearch::Persistence::Repository
- Defined in:
- lib/elasticsearch/persistence/repository.rb,
lib/elasticsearch/persistence/repository/dsl.rb,
lib/elasticsearch/persistence/repository/find.rb,
lib/elasticsearch/persistence/repository/store.rb,
lib/elasticsearch/persistence/repository/search.rb,
lib/elasticsearch/persistence/repository/serialize.rb,
lib/elasticsearch/persistence/repository/response/results.rb
Overview
The base Repository mixin. This module should be included in classes that represent an Elasticsearch repository.
Since:
-
6.0.0
Defined Under Namespace
Modules: ClassMethods , DSL , Find , Response , Search , Serialize , Store Classes: DocumentNotFound
Constant Summary collapse
- DEFAULT_INDEX_NAME =
The default index name.
Returns:
-
(String)
—
The default index name.
Since:
-
6.0.0
-
(String)
—
'repository'.freeze
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
The repository options.
Class Method Summary collapse
Instance Method Summary collapse
-
#client ⇒ Elasticsearch::Client
Get the client used by the repository.
-
#index_exists?(*args) ⇒ true, false
Determine whether the index with this repository’s index name exists.
-
#index_name ⇒ String, Symbol
Get the index name used by the repository.
-
#initialize(options = {}) ⇒ Object
Initialize a repository instance.
-
#inspect ⇒ String
Get the nicer formatted string for use in inspection.
-
#klass ⇒ Class
Get the class used by the repository when deserializing.
-
#mapping(*args) ⇒ Elasticsearch::Model::Indexing::Mappings
(also: #mappings)
Get the index mapping.
-
#settings(*args) ⇒ Elasticsearch::Model::Indexing::Settings
Get the index settings.
Methods included from Search
Methods included from Find
Methods included from Serialize
Methods included from Store
Instance Attribute Details
#options ⇒ Hash (readonly)
The repository options.
Returns:
- (Hash)
Since:
-
6.0.0
87 88 89
# File 'lib/elasticsearch/persistence/repository.rb', line 87 def options @options end
Class Method Details
.included(base) ⇒ Object
Since:
-
6.0.0
38 39 40
# File 'lib/elasticsearch/persistence/repository.rb', line 38 def self.included(base) base.send(:extend, ClassMethods ) end
Instance Method Details
#client ⇒ Elasticsearch::Client
Get the client used by the repository.
Examples:
repository.client
Returns:
-
(Elasticsearch::Client)
—
The repository’s client.
Since:
-
6.0.0
116 117 118 119 120
# File 'lib/elasticsearch/persistence/repository.rb', line 116 def client @client ||= @options[:client] || __get_class_value(:client) || Elasticsearch ::Client.new end
#index_exists?(*args) ⇒ true, false
Determine whether the index with this repository’s index name exists.
Examples:
repository.index_exists?
Returns:
-
(true, false)
—
Whether the index exists.
Since:
-
6.0.0
203 204 205
# File 'lib/elasticsearch/persistence/repository.rb', line 203 def index_exists?(*args) super end
#index_name ⇒ String, Symbol
Get the index name used by the repository.
Examples:
repository.index_name
Returns:
-
(String, Symbol)
—
The repository’s index name.
Since:
-
6.0.0
130 131 132 133 134
# File 'lib/elasticsearch/persistence/repository.rb', line 130 def index_name @index_name ||= @options[:index_name] || __get_class_value(:index_name) || DEFAULT_INDEX_NAME end
#initialize(options = {}) ⇒ Object
Initialize a repository instance.
Examples:
Initialize the repository.
Initialize the repository.
MyRepository.new(index_name: 'notes', klass: Note)
Parameters:
-
options
(Hash)
(defaults to: {})
—
The options to use.
Options Hash (options):
-
:index_name
(Symbol, String)
—
The name of the index.
-
:client
(Symbol, String)
—
The client used to handle requests to and from Elasticsearch.
-
:klass
(Symbol, String)
—
The class used to instantiate an object when documents are deserialized. The default is nil, in which case the raw document will be returned as a Hash.
-
:mapping
(Elasticsearch::Model::Indexing::Mappings, Hash)
—
The mapping for this index.
-
:settings
(Elasticsearch::Model::Indexing::Settings, Hash)
—
The settings for this index.
Since:
-
6.0.0
104 105 106
# File 'lib/elasticsearch/persistence/repository.rb', line 104 def initialize(options = {}) @options = options end
#inspect ⇒ String
Get the nicer formatted string for use in inspection.
Examples:
Inspect the repository.
Inspect the repository.
repository.inspect
Returns:
-
(String)
—
The repository inspection.
Since:
-
6.0.0
215 216 217
# File 'lib/elasticsearch/persistence/repository.rb', line 215 def inspect "#<#{self.class}:0x#{object_id} index_name=#{index_name} klass=#{klass}>" end
#klass ⇒ Class
Get the class used by the repository when deserializing.
Examples:
repository.klass
Returns:
-
(Class)
—
The repository’s klass for deserializing.
Since:
-
6.0.0
144 145 146
# File 'lib/elasticsearch/persistence/repository.rb', line 144 def klass @klass ||= @options[:klass] || __get_class_value(:klass) end
#mapping(*args) ⇒ Elasticsearch::Model::Indexing::Mappings Also known as: mappings
If mappings were set when the repository was created, a block passed to this method will not be evaluated.
Get the index mapping. Optionally pass a block to define the mappings.
end
Examples:
repository.mapping
Set the mappings with a block.
Set the mappings with a block.
repository.mapping dynamic: 'strict' do
indexes :foo
end
Returns:
-
(Elasticsearch::Model::Indexing::Mappings)
—
The index mappings.
Since:
-
6.0.0
165 166 167 168 169 170 171
# File 'lib/elasticsearch/persistence/repository.rb', line 165 def mapping(*args) @memoized_mapping ||= @options[:mapping] || (begin if _mapping = __get_class_value(:mapping) _mapping end end) || (super && @mapping) end
#settings(*args) ⇒ Elasticsearch::Model::Indexing::Settings
Get the index settings.
Examples:
repository.settings
Set the settings with a block.
Set the settings with a block.
repository.settings number_of_shards: 1, number_of_replicas: 0 do
mapping dynamic: 'strict' do
indexes :foo do
indexes :bar
end
end
end
Returns:
-
(Elasticsearch::Model::Indexing::Settings)
—
The index settings.
Since:
-
6.0.0
191 192 193
# File 'lib/elasticsearch/persistence/repository.rb', line 191 def settings(*args) @memoized_settings ||= @options[:settings] || __get_class_value(:settings) || (super && @settings) end