Skip to content

Commit 9472bc4

Browse files
committed
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: elastic/elasticsearch#6730
1 parent 17b9e19 commit 9472bc4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/logstash/outputs/elasticsearch.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base
4949
# similar events to the same 'type'. String expansion `%{foo}` works here.
5050
config :index_type, :validate => :string
5151

52+
# A routing override to be applied to all processed events.
53+
# This can be dynamic using the `%{foo}` syntax.
54+
config :routing, :validate => :string
55+
5256
# Starting in Logstash 1.3 (unless you set option `manage_template` to false)
5357
# a default mapping template for Elasticsearch will be applied, if you do not
5458
# already have one set to match the index pattern defined (default of
@@ -393,11 +397,11 @@ def receive(event)
393397

394398
# Set the 'type' value for the index.
395399
type = @index_type ? event.sprintf(@index_type) : (event["type"] || "logs")
396-
397400
index = event.sprintf(@index)
398-
399401
document_id = @document_id ? event.sprintf(@document_id) : nil
400-
buffer_receive([event.sprintf(@action), { :_id => document_id, :_index => index, :_type => type }, event])
402+
routing = @routing ? event.sprintf(@routing) : nil
403+
404+
buffer_receive([event.sprintf(@action), { :_id => document_id, :_index => index, :_type => type, :_routing => routing }, event])
401405
end # def receive
402406

403407
public

0 commit comments

Comments
 (0)