diff --git a/docs/index.asciidoc b/docs/index.asciidoc index bd44e2c..fea00b5 100644 --- a/docs/index.asciidoc +++ b/docs/index.asciidoc @@ -126,6 +126,7 @@ This plugin supports the following configuration options plus the <> |<>|No | <> |<>|No | <> |<>|No +| <> |<>|No | <> |<>|No | <> |<>|No | <> |<>|No @@ -190,13 +191,21 @@ Example: } [id="plugins-{type}s-{plugin}-enable_sort"] -===== `enable_sort` +===== `enable_sort` * Value type is <> * Default value is `true` Whether results should be sorted or not +[id="plugins-{type}s-{plugin}-include_hits"] +===== `include_hits` + + * Value type is <> + * Default value is `false` + +Whether the full list of hits should be applied to `[@metadata][hits]`. + [id="plugins-{type}s-{plugin}-fields"] ===== `fields` diff --git a/lib/logstash/filters/elasticsearch.rb b/lib/logstash/filters/elasticsearch.rb index 6de224e..9594468 100644 --- a/lib/logstash/filters/elasticsearch.rb +++ b/lib/logstash/filters/elasticsearch.rb @@ -64,6 +64,9 @@ class LogStash::Filters::Elasticsearch < LogStash::Filters::Base # Whether results should be sorted or not config :enable_sort, :validate => :boolean, :default => true + # Whether to set hits to metadata + config :include_hits, :validate => :boolean, :default => false + # How many results to return config :result_size, :validate => :number, :default => 1 @@ -116,6 +119,9 @@ def filter(event) resultsHits = results["hits"]["hits"] if !resultsHits.nil? && !resultsHits.empty? + if @include_hits + event.set("[@metadata][hits]", resultsHits) + end matched = true @fields.each do |old_key, new_key| old_key_path = extract_path(old_key)