1- # Elasticsearch ::Model
1+ # OpenSearch ::Model
22
33The ` opensearch-model ` library builds on top of the the [ ` elasticsearch ` ] ( https://github.com/elastic/elasticsearch-ruby ) library.
44
@@ -61,15 +61,15 @@ and include the main module in your class:
6161require ' opensearch/model'
6262
6363class Article < ActiveRecord ::Base
64- include Elasticsearch ::Model
64+ include OpenSearch ::Model
6565end
6666```
6767
6868This will extend the model with functionality related to Elasticsearch.
6969
7070#### Feature Extraction Pattern
7171
72- Instead of including the ` Elasticsearch ::Model` module directly in your model, you can include it in a "concern" or "trait" module, which is quite common pattern in Rails applications, using e.g. ` ActiveSupport::Concern ` as the instrumentation:
72+ Instead of including the ` OpenSearch ::Model` module directly in your model, you can include it in a "concern" or "trait" module, which is quite common pattern in Rails applications, using e.g. ` ActiveSupport::Concern ` as the instrumentation:
7373
7474``` ruby
7575# In: app/models/concerns/searchable.rb
@@ -78,7 +78,7 @@ module Searchable
7878 extend ActiveSupport ::Concern
7979
8080 included do
81- include Elasticsearch ::Model
81+ include OpenSearch ::Model
8282
8383 mapping do
8484 # ...
9999
100100#### The ` __elasticsearch__ ` Proxy
101101
102- The ` Elasticsearch ::Model` module contains a big amount of class and instance methods to provide
102+ The ` OpenSearch ::Model` module contains a big amount of class and instance methods to provide
103103all its functionality. To prevent polluting your model namespace, this functionality is primarily
104104available via the ` __elasticsearch__ ` class and instance level proxy methods;
105- see the ` Elasticsearch ::Model::Proxy` class documentation for technical information.
105+ see the ` OpenSearch ::Model::Proxy` class documentation for technical information.
106106
107107The module will include important methods, such as ` search ` , into the class or module only
108108when they haven't been defined already. Following two calls are thus functionally equivalent:
@@ -112,7 +112,7 @@ Article.__elasticsearch__.search 'fox'
112112Article .search ' fox'
113113```
114114
115- See the ` Elasticsearch ::Model` module documentation for technical information.
115+ See the ` OpenSearch ::Model` module documentation for technical information.
116116
117117### The Elasticsearch client
118118
@@ -133,7 +133,7 @@ Article.__elasticsearch__.client = OpenSearch::Client.new host: 'api.server.org'
133133Or configure the client for all models:
134134
135135``` ruby
136- Elasticsearch ::Model .client = OpenSearch ::Client .new log: true
136+ OpenSearch ::Model .client = OpenSearch ::Client .new log: true
137137```
138138
139139You might want to do this during your application bootstrap process, e.g. in a Rails initializer.
@@ -194,7 +194,7 @@ response.results.map { |r| r._source.title }
194194# => ["Quick brown fox", "Fast black dogs"]
195195
196196response.results.select { |r | r.title =~ /^Q/ }
197- # => [#<Elasticsearch ::Model::Response::Result:0x007 ... "_source"=>{"title"=>"Quick brown fox"}}>]
197+ # => [#<OpenSearch ::Model::Response::Result:0x007 ... "_source"=>{"title"=>"Quick brown fox"}}>]
198198```
199199
200200In fact, the ` response ` object will delegate ` Enumerable ` methods to ` results ` :
@@ -265,19 +265,19 @@ response.records.each_with_hit { |record, hit| puts "* #{record.title}: #{hit._s
265265It is possible to search across multiple models with the module method:
266266
267267``` ruby
268- Elasticsearch ::Model .search(' fox' , [Article , Comment ]).results.to_a.map(& :to_hash )
268+ OpenSearch ::Model .search(' fox' , [Article , Comment ]).results.to_a.map(& :to_hash )
269269# => [
270270# {"_index"=>"articles", "_type"=>"article", "_id"=>"1", "_score"=>0.35136628, "_source"=>...},
271271# {"_index"=>"comments", "_type"=>"comment", "_id"=>"1", "_score"=>0.35136628, "_source"=>...}
272272# ]
273273
274- Elasticsearch ::Model .search(' fox' , [Article , Comment ]).records.to_a
274+ OpenSearch ::Model .search(' fox' , [Article , Comment ]).records.to_a
275275# Article Load (0.3ms) SELECT "articles".* FROM "articles" WHERE "articles"."id" IN (1)
276276# Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."id" IN (1,5)
277277# => [#<Article id: 1, title: "Quick brown fox">, #<Comment id: 1, body: "Fox News">, ...]
278278```
279279
280- By default, all models which include the ` Elasticsearch ::Model` module are searched.
280+ By default, all models which include the ` OpenSearch ::Model` module are searched.
281281
282282NOTE: It is _ not_ possible to chain other methods on top of the ` records ` object, since it
283283 is a heterogenous collection, with models potentially backed by different databases.
@@ -308,7 +308,7 @@ To initialize and include the Kaminari pagination support manually:
308308
309309``` ruby
310310Kaminari ::Hooks .init if defined? (Kaminari ::Hooks )
311- Elasticsearch ::Model ::Response ::Response .__send__ :include , Elasticsearch ::Model ::Response ::Pagination ::Kaminari
311+ OpenSearch ::Model ::Response ::Response .__send__ :include , OpenSearch ::Model ::Response ::Pagination ::Kaminari
312312```
313313
314314#### The Elasticsearch DSL
@@ -348,7 +348,7 @@ Also, you can use the [**`elasticsearch-dsl`**](https://github.com/elastic/elast
348348``` ruby
349349require ' opensearch/dsl'
350350
351- query = Elasticsearch ::DSL ::Search .search do
351+ query = OpenSearch ::DSL ::Search .search do
352352 query do
353353 match :title do
354354 query ' fox dogs'
@@ -364,7 +364,7 @@ response.results.first.title
364364### Index Configuration
365365
366366For proper search engine function, it's often necessary to configure the index properly.
367- The ` Elasticsearch ::Model` integration provides class methods to set up index settings and mappings.
367+ The ` OpenSearch ::Model` integration provides class methods to set up index settings and mappings.
368368
369369** NOTE** : Elasticsearch will automatically create an index when a document is indexed,
370370 with default settings and mappings. Create the index in advance with the ` create_index! `
@@ -436,12 +436,12 @@ Article.first.__elasticsearch__.index_document
436436#### Automatic Callbacks
437437
438438You can automatically update the index whenever the record changes, by including
439- the ` Elasticsearch ::Model::Callbacks` module in your model:
439+ the ` OpenSearch ::Model::Callbacks` module in your model:
440440
441441``` ruby
442442class Article
443- include Elasticsearch ::Model
444- include Elasticsearch ::Model ::Callbacks
443+ include OpenSearch ::Model
444+ include OpenSearch ::Model ::Callbacks
445445end
446446
447447Article .first.update_attribute :title , ' Updated!'
@@ -454,7 +454,7 @@ The automatic callback on record update keeps track of changes in your model
454454(via [ ` ActiveModel::Dirty ` ] ( http://api.rubyonrails.org/classes/ActiveModel/Dirty.html ) -compliant implementation),
455455and performs a _ partial update_ when this support is available.
456456
457- The automatic callbacks are implemented in database adapters coming with ` Elasticsearch ::Model` . You can easily
457+ The automatic callbacks are implemented in database adapters coming with ` OpenSearch ::Model` . You can easily
458458implement your own adapter: please see the relevant chapter below.
459459
460460#### Custom Callbacks
@@ -464,7 +464,7 @@ by hooking into `after_create`, `after_save`, `after_update` or `after_destroy`
464464
465465``` ruby
466466class Article
467- include Elasticsearch ::Model
467+ include OpenSearch ::Model
468468
469469 after_save { logger.debug [" Updating document... " , index_document ].join }
470470 after_destroy { logger.debug [" Deleting document... " , delete_document].join }
@@ -476,7 +476,7 @@ your data against inconsistencies caused by transaction rollbacks:
476476
477477``` ruby
478478class Article < ActiveRecord ::Base
479- include Elasticsearch ::Model
479+ include OpenSearch ::Model
480480
481481 after_commit on: [:create ] do
482482 __elasticsearch__ .index_document if self .published?
@@ -504,7 +504,7 @@ with a tool like [_Resque_](https://github.com/resque/resque) or [_Sidekiq_](htt
504504
505505``` ruby
506506class Article
507- include Elasticsearch ::Model
507+ include OpenSearch ::Model
508508
509509 after_save { Indexer .perform_async(:index , self .id) }
510510 after_destroy { Indexer .perform_async(:delete , self .id) }
@@ -560,7 +560,7 @@ Indexer JID-eb7e2daf389a1e5e83697128 INFO: done: 0.006 sec
560560### Model Serialization
561561
562562By default, the model instance will be serialized to JSON using the ` as_indexed_json ` method,
563- which is defined automatically by the ` Elasticsearch ::Model::Serializing` module:
563+ which is defined automatically by the ` OpenSearch ::Model::Serializing` module:
564564
565565``` ruby
566566Article .first.__elasticsearch__ .as_indexed_json
@@ -572,7 +572,7 @@ for instance with the [`as_json`](http://api.rubyonrails.org/classes/ActiveModel
572572
573573``` ruby
574574class Article
575- include Elasticsearch ::Model
575+ include OpenSearch ::Model
576576
577577 def as_indexed_json (options = {})
578578 as_json(only: ' title' )
@@ -619,7 +619,7 @@ _ActiveRecord_ callbacks -- please see the full example in `examples/activerecor
619619
620620### Other ActiveModel Frameworks
621621
622- The ` Elasticsearch ::Model` module is fully compatible with any ActiveModel-compatible model, such as _ Mongoid_ :
622+ The ` OpenSearch ::Model` module is fully compatible with any ActiveModel-compatible model, such as _ Mongoid_ :
623623
624624``` ruby
625625require ' mongoid'
@@ -634,7 +634,7 @@ class Article
634634
635635 attr_accessible :id , :title , :published_at
636636
637- include Elasticsearch ::Model
637+ include OpenSearch ::Model
638638
639639 def as_indexed_json (options = {})
640640 as_json(except: [:id , :_id ])
@@ -655,7 +655,7 @@ Full examples for CouchBase, DataMapper, Mongoid, Ohm and Riak models can be fou
655655### Adapters
656656
657657To support various "OxM" (object-relational- or object-document-mapper) implementations and frameworks,
658- the ` Elasticsearch ::Model` integration supports an "adapter" concept.
658+ the ` OpenSearch ::Model` integration supports an "adapter" concept.
659659
660660An adapter provides implementations for common behaviour, such as fetching records from the database,
661661hooking into model callbacks for automatic index updates, or efficient bulk loading from the database.
@@ -680,20 +680,20 @@ end
680680
681681# Register the adapter
682682#
683- Elasticsearch ::Model ::Adapter .register(
683+ OpenSearch ::Model ::Adapter .register(
684684 DataMapperAdapter ,
685685 lambda { |klass | defined? (::DataMapper ::Resource ) and klass.ancestors.include?(::DataMapper ::Resource ) }
686686)
687687```
688688
689- Require the adapter and include ` Elasticsearch ::Model` in the class:
689+ Require the adapter and include ` OpenSearch ::Model` in the class:
690690
691691``` ruby
692692require ' datamapper_adapter'
693693
694694class Article
695695 include DataMapper ::Resource
696- include Elasticsearch ::Model
696+ include OpenSearch ::Model
697697
698698 property :id , Serial
699699 property :title , String
@@ -714,7 +714,7 @@ response.records.records.class
714714# => DataMapper::Collection
715715```
716716
717- More examples can be found in the ` examples ` folder. Please see the ` Elasticsearch ::Model::Adapter`
717+ More examples can be found in the ` examples ` folder. Please see the ` OpenSearch ::Model::Adapter`
718718module and its submodules for technical information.
719719
720720### Settings
0 commit comments