class Krikri::ProdSearchIndex

Production ElasticSearch search index class

Attributes

elasticsearch[R]
index_name[R]

Public Class Methods

new(opts = {}) click to toggle source

@param [Hash] opts

Options used by this class:

- index_name [String]  The name of the ElasticSearch index

Other options are passed along to Elasticsearch::Client.

Calls superclass method Krikri::SearchIndex::new
# 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

Public Instance Methods

bulk_add(docs) click to toggle source

Add a number of JSON documents to the search index at once. @param docs [Array] Array of hashes that can be serialized with to_json

# 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) click to toggle source

@see Krikri::SearchIndex#hash_for_index_schema

# File lib/krikri/search_index.rb, line 345
def hash_for_index_schema(aggregation)
  aggregation.to_3_1_json
end
update_from_activity(activity) click to toggle source

@see Krikri::SearchIndex#update_from_activity

# 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