Class: Bas::SharedStorage::Elasticsearch

Inherits:
Base
  • Object
show all
Defined in:
lib/bas/shared_storage/elasticsearch.rb

Overview

The SharedStorage::Elasticsearch class serves as a shared storage implementation to read and write on a shared storage defined as a elasticsearch database

Instance Attribute Summary

Attributes inherited from Base

#read_options, #read_response, #write_options, #write_response

Instance Method Summary collapse

Methods inherited from Base

#close_connections, #initialize

Constructor Details

This class inherits a constructor from Bas::SharedStorage::Base

Instance Method Details

#readObject



15
16
17
18
19
20
21
22
23
# File 'lib/bas/shared_storage/elasticsearch.rb', line 15

def read
  params = {
    connection: read_options[:connection], index: read_options[:index],
    query: read_body, method: :search
  }

  result = Utils::Elasticsearch::Request.execute(params)
  @read_response = build_read_response(result)
end

#set_in_processObject



35
36
37
38
39
# File 'lib/bas/shared_storage/elasticsearch.rb', line 35

def set_in_process
  return if read_options[:avoid_process].eql?(true) || read_response.id.nil?

  update_stage(read_response.id, "in process")
end

#set_processedObject



41
42
43
44
45
# File 'lib/bas/shared_storage/elasticsearch.rb', line 41

def set_processed
  return if read_options[:avoid_process].eql?(true) || read_response.id.nil?

  update_stage(read_response.id, "processed")
end

#write(data) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/bas/shared_storage/elasticsearch.rb', line 25

def write(data)
  params = {
    connection: write_options[:connection], index: write_options[:index],
    body: write_body(data), method: :index
  }

  create_mapping
  @write_response = Utils::Elasticsearch::Request.execute(params).body
end