Class: Krikri::ProdSearchIndex
- Inherits:
-
SearchIndex
- Object
- SearchIndex
- Krikri::ProdSearchIndex
- Defined in:
- lib/krikri/search_index.rb
Overview
Production ElasticSearch search index class
Instance Attribute Summary collapse
-
#elasticsearch ⇒ Object
readonly
Returns the value of attribute elasticsearch.
-
#index_name ⇒ Object
readonly
Returns the value of attribute index_name.
Instance Method Summary collapse
-
#bulk_add(docs) ⇒ Object
Add a number of JSON documents to the search index at once.
- #hash_for_index_schema(aggregation) ⇒ Object
-
#initialize(opts = {}) ⇒ ProdSearchIndex
constructor
Options used by this class: - index_name [String] The name of the ElasticSearch index Other options are passed along to Elasticsearch::Client.
- #update_from_activity(activity) ⇒ Object
Methods inherited from SearchIndex
Constructor Details
#initialize(opts = {}) ⇒ ProdSearchIndex
Options used by this class:
- index_name [String] The name of the ElasticSearch index
Other options are passed along to Elasticsearch::Client.
311 312 313 314 315 316 |
# File 'lib/krikri/search_index.rb', line 311 def initialize(opts = {}) = Krikri::Settings.elasticsearch.to_h.merge(opts) super() @index_name = .delete(:index_name) { 'dpla_alias' } @elasticsearch = Elasticsearch::Client.new() end |
Instance Attribute Details
#elasticsearch ⇒ Object (readonly)
Returns the value of attribute elasticsearch.
302 303 304 |
# File 'lib/krikri/search_index.rb', line 302 def elasticsearch @elasticsearch end |
#index_name ⇒ Object (readonly)
Returns the value of attribute index_name.
302 303 304 |
# File 'lib/krikri/search_index.rb', line 302 def index_name @index_name end |
Instance Method Details
#bulk_add(docs) ⇒ Object
Add a number of JSON documents to the search index at once.
321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/krikri/search_index.rb', line 321 def bulk_add(docs) body = docs.map do |doc| { index: { _index: @index_name, _type: doc[:ingestType], _id: doc[:id], data: doc } } end @elasticsearch.bulk body: body end |
#hash_for_index_schema(aggregation) ⇒ Object
345 346 347 |
# File 'lib/krikri/search_index.rb', line 345 def hash_for_index_schema(aggregation) aggregation.to_3_1_json end |