From 9472bc41b064322e60e649c7987d6c0a723e25d0 Mon Sep 17 00:00:00 2001 From: Myles Steinhauser Date: Fri, 27 Feb 2015 21:36:52 +0100 Subject: [PATCH] Support routing option for documents The bulk API supports a specified `_routing` value for document placement within a shard in an index. This should be exposed for custom routing for aliases, filtering, etc. http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html#bulk-routing This also respects the move away from the routing parameter within the event as defined in: https://github.com/elasticsearch/elasticsearch/issues/6730 --- lib/logstash/outputs/elasticsearch.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/logstash/outputs/elasticsearch.rb b/lib/logstash/outputs/elasticsearch.rb index bd1cf2f09..0e2411d24 100644 --- a/lib/logstash/outputs/elasticsearch.rb +++ b/lib/logstash/outputs/elasticsearch.rb @@ -49,6 +49,10 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base # similar events to the same 'type'. String expansion `%{foo}` works here. config :index_type, :validate => :string + # A routing override to be applied to all processed events. + # This can be dynamic using the `%{foo}` syntax. + config :routing, :validate => :string + # Starting in Logstash 1.3 (unless you set option `manage_template` to false) # a default mapping template for Elasticsearch will be applied, if you do not # already have one set to match the index pattern defined (default of @@ -393,11 +397,11 @@ def receive(event) # Set the 'type' value for the index. type = @index_type ? event.sprintf(@index_type) : (event["type"] || "logs") - index = event.sprintf(@index) - document_id = @document_id ? event.sprintf(@document_id) : nil - buffer_receive([event.sprintf(@action), { :_id => document_id, :_index => index, :_type => type }, event]) + routing = @routing ? event.sprintf(@routing) : nil + + buffer_receive([event.sprintf(@action), { :_id => document_id, :_index => index, :_type => type, :_routing => routing }, event]) end # def receive public