mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Merge pull request #286 from michaelgibson/master
adding ability to define the event.id in a custom filter for the elasticsearch output. LOGSTASH-256
This commit is contained in:
commit
ab6d971966
2 changed files with 13 additions and 1 deletions
|
@ -125,6 +125,9 @@ class LogStash::Event
|
|||
def tags; @data["@tags"]; end # def tags
|
||||
def tags=(val); @data["@tags"] = val; end # def tags=
|
||||
|
||||
def id; @data["@id"]; end # def id
|
||||
def id=(val); @data["@id"] = val; end # def id=
|
||||
|
||||
# field-related access
|
||||
public
|
||||
def [](key)
|
||||
|
|
|
@ -37,6 +37,9 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
|
|||
# similar events to the same 'type'. String expansion '%{foo}' works here.
|
||||
config :index_type, :validate => :string, :default => "%{@type}"
|
||||
|
||||
# The document ID for the index. Overwrites any existing entry in elasticsearch with the same ID.
|
||||
config :id, :validate => :string, :default => nil
|
||||
|
||||
# The name of your cluster if you set it on the ElasticSearch side. Useful
|
||||
# for discovery.
|
||||
config :cluster, :validate => :string
|
||||
|
@ -160,7 +163,13 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
|
|||
end
|
||||
end
|
||||
|
||||
req = @client.index(index, type, event.to_hash)
|
||||
if id.nil?
|
||||
req = @client.index(index, type, event.to_hash)
|
||||
else
|
||||
id = event.sprintf(@id)
|
||||
req = @client.index(index, type, id, event.to_hash)
|
||||
end
|
||||
|
||||
increment_inflight_request_count
|
||||
#timer = @logger.time("elasticsearch write")
|
||||
req.on(:success) do |response|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue