Module: Elasticsearch::Persistence::Repository::ClassMethods
- Defined in:
- lib/elasticsearch/persistence/repository.rb
Overview
Since:
-
6.0.0
Instance Method Summary collapse
-
#create(options = {}, &block) ⇒ Object
Initialize a repository instance.
Instance Method Details
#create(options = {}, &block) ⇒ Object
Initialize a repository instance. Optionally provide a block to define index mappings or
settings on the repository instance.
Examples:
Create a new repository.
Create a new repository.
MyRepository.create(index_name: 'notes', klass: Note)
Create a new repository and evaluate a block on it.
Create a new repository and evaluate a block on it.
MyRepository.create(index_name: 'notes', klass: Note) do
mapping dynamic: 'strict' do
indexes :title
end
end
Parameters:
-
options
(Hash)
(defaults to: {})
—
The options to use.
-
block
(Proc)
—
A block to evaluate on the new repository instance.
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
68 69 70 71 72
# File 'lib/elasticsearch/persistence/repository.rb', line 68 def create(options = {}, &block) new(options).tap do |obj| obj.instance_eval(&block) if block_given? end end