Module: SolrUtil

Included in:
Fluent::SolrOutput, Fluent::SolrTimeSlicedOutput
Defined in:
lib/fluent/plugin/solr_util.rb

Overview

Solr utility

Instance Method Summary collapse

Instance Method Details

#update_core(chunk, core) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fluent/plugin/solr_util.rb', line 7

def update_core(chunk, core)
  documents = []

  chunk.msgpack_each do |tag, unixtime, record|
    time = Time.at(unixtime)
    time = time.utc unless @localtime
    record.merge!(@time_field => time.strftime('%FT%TZ'))
    record.merge!(@tag_key    => tag) if @include_tag_key
    documents << record
  end

  http = Net::HTTP.new(@host, @port.to_i)
  url = '/solr/' + URI.escape(core) + '/update'
  url += '?commit=true' if @commit
  request = Net::HTTP::Post.new(url, 'content-type' => 'application/json; charset=utf-8')
  request.body = Yajl::Encoder.encode(documents)
  http.request(request).value
end