Class: Peek::Adapters::Elasticsearch

Inherits:
Base
  • Object
show all
Defined in:
lib/peek/adapters/elasticsearch.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Elasticsearch

Returns a new instance of Elasticsearch.



7
8
9
10
11
12
# File 'lib/peek/adapters/elasticsearch.rb', line 7

def initialize(options = {})
  @client = options.fetch(:client, ::Elasticsearch::Client.new)
  @expires_in = Integer(options.fetch(:expires_in, 60 * 30) * 1000)
  @index = options.fetch(:index, 'peek_requests_index')
  @type = options.fetch(:type, 'peek_request')
end

Instance Method Details

#get(request_id) ⇒ Object



14
15
16
17
18
19
# File 'lib/peek/adapters/elasticsearch.rb', line 14

def get(request_id)
  result = @client.get_source index: @index, type: @type, id: "#{request_id}"
  result.to_json
rescue ::Elasticsearch::Transport::Transport::Errors::NotFound
  # pass
end

#saveObject



21
22
23
24
25
26
27
28
29
# File 'lib/peek/adapters/elasticsearch.rb', line 21

def save
  @client.index index: @index,
                type: @type,
                id: "#{Peek.request_id}",
                body: Peek.results.to_json,
                ttl: @expires_in
rescue ::Elasticsearch::Transport::Transport::Errors::BadRequest
  false
end