lib/fluent/plugin/out_solr.rb in fluent-plugin-output-solr-1.0.2 vs lib/fluent/plugin/out_solr.rb in fluent-plugin-output-solr-1.0.3

- old
+ new

@@ -91,10 +91,16 @@ elsif @mode == MODE_SOLRCLOUD then @zk = ZK.new(@zk_host) cloud_connection = RSolr::Cloud::Connection.new(@zk) @solr = RSolr::Client.new(cloud_connection, read_timeout: 60, open_timeout: 60) end + + # Get unique key field from Solr + @unique_key = get_unique_key + + # Get fields from Solr + @fields = get_fields end def shutdown super @@ -116,25 +122,19 @@ end def write(chunk) documents = [] - # Get fields from Solr - fields = get_fields - - # Get unique key field from Solr - unique_key = get_unique_key - # Get fluentd tag tag = chunk.metadata.tag chunk.msgpack_each do |time, record| record = inject_values_to_record(tag, time, record) # Set unique key and value - unless record.has_key?(unique_key) then - record.merge!({unique_key => SecureRandom.uuid}) + unless record.has_key?(@unique_key) then + record.merge!({@unique_key => SecureRandom.uuid}) end # Set Fluentd tag to Solr tag field unless record.has_key?(@tag_field) then record.merge!({@tag_field => tag}) @@ -157,10 +157,10 @@ end # Ignore undefined fields if @ignore_undefined_fields then record.each_key do |key| - unless fields.include?(key) then + unless @fields.include?(key) then record.delete(key) end end end