Class: Krikri::ProdSearchIndex

Inherits:
SearchIndex show all
Defined in:
lib/krikri/search_index.rb

Overview

Production ElasticSearch search index class

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SearchIndex

#add

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.

Parameters:

  • opts (Hash) (defaults to: {})


311
312
313
314
315
316
# File 'lib/krikri/search_index.rb', line 311

def initialize(opts = {})
  options = Krikri::Settings.elasticsearch.to_h.merge(opts)
  super(options)
  @index_name = options.delete(:index_name) { 'dpla_alias' }
  @elasticsearch = Elasticsearch::Client.new(options)
end

Instance Attribute Details

#elasticsearchObject (readonly)

Returns the value of attribute elasticsearch.



302
303
304
# File 'lib/krikri/search_index.rb', line 302

def elasticsearch
  @elasticsearch
end

#index_nameObject (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.

Parameters:

  • docs (Array)

    Array of hashes that can be serialized with #to_json



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

See Also:

  • SearchIndex#hash_for_index_schema


345
346
347
# File 'lib/krikri/search_index.rb', line 345

def hash_for_index_schema(aggregation)
  aggregation.to_3_1_json
end

#update_from_activity(activity) ⇒ Object



337
338
339
340
341
# File 'lib/krikri/search_index.rb', line 337

def update_from_activity(activity)
  fail "#{activity} is not an Activity" \
    unless activity.class == Krikri::Activity
  bulk_update_from_activity(activity)
end