Class: LogStash::Codecs::ESBulk

Inherits:
Base
  • Object
show all
Extended by:
PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
Includes:
PluginMixins::ECSCompatibilitySupport::TargetCheck, PluginMixins::EventSupport::EventFactoryAdapter
Defined in:
lib/logstash/codecs/es_bulk.rb

Overview

This codec will decode the http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html[Elasticsearch bulk format] into individual events, plus metadata into the @metadata field.

Encoding is not supported at this time as the Elasticsearch output submits Logstash events in bulk format.

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ ESBulk

Returns a new instance of ESBulk.



33
34
35
36
37
38
39
40
# File 'lib/logstash/codecs/es_bulk.rb', line 33

def initialize(params={})
  super(params)
  @lines = LogStash::Codecs::Line.new
  @lines.charset = "UTF-8"
  @state = :initial
   = Hash.new
   = ecs_select[disabled: '[@metadata]', v1: '[@metadata][codec][es_bulk]']
end

Instance Method Details

#decode(data) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/logstash/codecs/es_bulk.rb', line 46

def decode(data)
  @lines.decode(data) do |bulk|
    begin
      line = LogStash::Json.load(bulk.get("message"))
      case @state
      when :metadata
        event = targeted_event_factory.new_event(line)
        event.set(, )
        yield event
        @state = :initial
      when :initial
         = line[line.keys[0]]
        ["action"] = line.keys[0].to_s
        @state = :metadata
        if line.keys[0] == 'delete'
          event = targeted_event_factory.new_event
          event.set(, )
          yield event
          @state = :initial
        end
      end
    rescue LogStash::Json::ParserError => e
      @logger.error("JSON parse failure. ES Bulk messages must in be UTF-8 JSON", :error => e, :data => data)
    end
  end
end

#registerObject



42
43
# File 'lib/logstash/codecs/es_bulk.rb', line 42

def register
end