77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/elastictastic/bulk_persistence_strategy.rb', line 77
def flush
return if @operations.empty?
params = {}
params[:refresh] = true if Elastictastic.config.auto_refresh
io = StringIO.new
operations = @operations.reject { |operation| operation.skip }
@operations.clear
operations.each do |operation|
operation.commands.each do |command|
io.puts Elastictastic.json_encode(command)
end
end
response = Elastictastic.client.bulk(io.string, params)
response['items'].each_with_index do |op_response, i|
operation = operations[i]
operation.handler.call(op_response) if operation.handler
end
response
end
|