in elasticsearch-api/lib/elasticsearch/api/actions/bulk.rb [155:193]
def bulk(arguments = {})
request_opts = { endpoint: arguments[:endpoint] || 'bulk' }
defined_params = [:index].each_with_object({}) do |variable, set_variables|
set_variables[variable] = arguments[variable] if arguments.key?(variable)
end
request_opts[:defined_params] = defined_params unless defined_params.empty?
raise ArgumentError, "Required argument 'body' missing" unless arguments[:body]
arguments = arguments.clone
headers = arguments.delete(:headers) || {}
body = arguments.delete(:body)
_index = arguments.delete(:index)
method = Elasticsearch::API::HTTP_POST
path = if _index
"#{Utils.listify(_index)}/_bulk"
else
'_bulk'
end
params = Utils.process_params(arguments)
payload = if body.is_a? Array
Elasticsearch::API::Utils.bulkify(body)
else
body
end
headers.merge!({
'Content-Type' => 'application/vnd.elasticsearch+x-ndjson; compatible-with=9'
})
Elasticsearch::API::Response.new(
perform_request(method, path, params, payload, headers, request_opts)
)
end