Class: LogStash::Outputs::EsGroom::EsAccessor

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/elasticsearch_groom/es_accessor.rb

Overview

Abstracts the connectivity to Elasticsearch and the ES specific operations.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ EsAccessor

Returns a new instance of EsAccessor.



7
8
9
# File 'lib/logstash/outputs/elasticsearch_groom/es_accessor.rb', line 7

def initialize(options={})
  @client = Elasticsearch::Client.new host: options[:host]
end

Instance Method Details

#close_indices(indices) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/logstash/outputs/elasticsearch_groom/es_accessor.rb', line 12

def close_indices(indices)
  return if indices.empty?

  # close doesn't accept a list, so iterate to pull it off
  indices.each do |i|
    @client.indices.close index: i
  end
end

#delete_indices(indices) ⇒ Object



22
23
24
25
# File 'lib/logstash/outputs/elasticsearch_groom/es_accessor.rb', line 22

def delete_indices(indices)
  return if indices.empty?
  @client.indices.delete index: indices
end

#matching_indices(pattern = '_all', scope = 'open') ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/logstash/outputs/elasticsearch_groom/es_accessor.rb', line 28

def matching_indices(pattern='_all', scope='open')

  # Need to emulate 'both'
  resolved_scope = scope == 'both' ? %w(open closed) : scope

  begin
    full_results = @client.indices.get index: pattern, expand_wildcards: resolved_scope
    full_results.keys
  rescue Elasticsearch::Transport::Transport::Errors::BadRequest
    # This gets raised when no indices match the given pattern
    return []
  end
end