Class: Logtastic::ECS

Inherits:
Object
  • Object
show all
Defined in:
lib/logtastic/ecs.rb

Instance Method Summary collapse

Constructor Details

#initialize(index: nil, template: nil, ilm: nil, version: "1.5", output: :default) ⇒ ECS

Returns a new instance of ECS.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/logtastic/ecs.rb', line 7

def initialize(index: nil, template: nil, ilm: nil, version: "1.5", output: :default)
  @index = index
  @output = output
  @elasticsearch = Logtastic.client(@output)

  @setup = Logtastic::Setup.new(
    @elasticsearch,
    template: { json: { path: File.new(template_path(version)) } }.merge(template || {}),
    ilm: ilm
  )
  @setup.perform!
end

Instance Method Details

#count(**args) ⇒ Object



32
33
34
# File 'lib/logtastic/ecs.rb', line 32

def count(**args)
  @elasticsearch.count({ index: query_index }.merge(**args))
end

#query_indexObject



36
37
38
39
40
41
42
# File 'lib/logtastic/ecs.rb', line 36

def query_index
  if @setup.ilm_enabled?
    "#{@setup.rollover_alias}-*"
  else
    @setup.template_pattern
  end
end

#search(**args) ⇒ Object



28
29
30
# File 'lib/logtastic/ecs.rb', line 28

def search(**args)
  @elasticsearch.search({ index: query_index }.merge(**args))
end

#write(event) ⇒ Object



20
21
22
# File 'lib/logtastic/ecs.rb', line 20

def write(event)
  Logtastic.write(@output, index: write_index(event), body: event)
end

#write_now(event) ⇒ Object



24
25
26
# File 'lib/logtastic/ecs.rb', line 24

def write_now(event)
  @elasticsearch.index(index: write_index(event), body: event)
end