Class: LogStash::Inputs::Elasticsearch
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::Elasticsearch
- Defined in:
- lib/logstash/inputs/elasticsearch.rb
Overview
Read from an Elasticsearch cluster, based on search query results. This is useful for replaying test logs, reindexing, etc.
Example:
- source,ruby
-
input {
# Read all documents from Elasticsearch matching the given query elasticsearch { hosts => "localhost" query => '{ "query": { "match": { "statuscode": 200 } }, "sort": [ "_doc" ] }' }}
This would create an Elasticsearch query with the following format:
- source,json
-
curl ‘localhost:9200/logstash-*/_search?&scroll=1m&size=1000’ -d ‘{
"query": { "match": { "statuscode": 200 } }, "sort": [ "_doc" ]}‘
Instance Method Summary collapse
Instance Method Details
#register ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/logstash/inputs/elasticsearch.rb', line 107 def register require "elasticsearch" = { :index => @index, :body => @query, :scroll => @scroll, :size => @size } = {} if @user && @password token = Base64.strict_encode64("#{@user}:#{@password.value}") [:headers] = { :Authorization => "Basic #{token}" } end hosts = if @ssl then @hosts.map do |h| host, port = h.split(":") { :host => host, :scheme => 'https', :port => port } end else @hosts end if @ssl && @ca_file [:ssl] = { :ca_file => @ca_file } end @client = Elasticsearch::Client.new(:hosts => hosts, :transport_options => ) end |
#run(output_queue) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/logstash/inputs/elasticsearch.rb', line 140 def run(output_queue) # get first wave of data r = @client.search() r['hits']['hits'].each { |hit| push_hit(hit, output_queue) } has_hits = r['hits']['hits'].any? while has_hits && !stop? r = process_next_scroll(output_queue, r['_scroll_id']) has_hits = r['has_hits'] end end |