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 = Krikri::Settings.elasticsearch.to_h) ⇒ 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 = Krikri::Settings.elasticsearch.to_h) ⇒ ProdSearchIndex
Options used by this class:
- index_name [String] The name of the ElasticSearch index
Other options are passed along to Elasticsearch::Client.
286 287 288 289 290 |
# File 'lib/krikri/search_index.rb', line 286 def initialize(opts = Krikri::Settings.elasticsearch.to_h) super(opts) @index_name = opts.delete(:index_name) { 'dpla_alias' } @elasticsearch = Elasticsearch::Client.new(opts) end |
Instance Attribute Details
#elasticsearch ⇒ Object (readonly)
Returns the value of attribute elasticsearch.
277 278 279 |
# File 'lib/krikri/search_index.rb', line 277 def elasticsearch @elasticsearch end |
#index_name ⇒ Object (readonly)
Returns the value of attribute index_name.
277 278 279 |
# File 'lib/krikri/search_index.rb', line 277 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.
295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/krikri/search_index.rb', line 295 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
319 320 321 322 323 324 |
# File 'lib/krikri/search_index.rb', line 319 def hash_for_index_schema(aggregation) graph = aggregation.to_jsonld['@graph'][0] # TODO: munge graph to MAPv3 # update search_index_spec.rb when that's done. graph end |