Class: AgnosticBackend::Elasticsearch::Indexer

Inherits:
Indexer
  • Object
show all
Includes:
Utilities
Defined in:
lib/agnostic_backend/elasticsearch/indexer.rb

Instance Attribute Summary

Attributes inherited from Indexer

#index

Instance Method Summary collapse

Methods included from Utilities

included

Methods inherited from Indexer

#delete, #delete_all, #generate_document, #initialize, #put, #put_all

Constructor Details

This class inherits a constructor from AgnosticBackend::Indexer

Instance Method Details

#publish(document) ⇒ Object



6
7
8
9
10
# File 'lib/agnostic_backend/elasticsearch/indexer.rb', line 6

def publish(document)
  client.send_request(:put,
                      path: "/#{index.index_name}/#{index.type}/#{document["id"]}",
                      body: document)
end

#publish_all(documents) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
# File 'lib/agnostic_backend/elasticsearch/indexer.rb', line 12

def publish_all(documents)
  return if documents.empty?
  response = client.send_request(:post,
                                 path: "/#{index.index_name}/#{index.type}/_bulk",
                                 body: convert_to_bulk_upload_string(documents))
  body = ActiveSupport::JSON.decode(response.body) rescue {}
  # if at least one indexing attempt fails, raise the red flag
  raise IndexingError.new, "Error in bulk upload" if body["errors"]
  response
end