bulk

in lib/elasticsearch-serverless/api/bulk.rb [134:170]


      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 = ElasticsearchServerless::API::HTTP_POST
        path   = if _index
                   "#{Utils.listify(_index)}/_bulk"
                 else
                   '_bulk'
                 end
        params = Utils.process_params(arguments)

        payload = if body.is_a? Array
                    ElasticsearchServerless::API::Utils.bulkify(body)
                  else
                    body
                  end

        headers.merge!('Content-Type' => 'application/x-ndjson')
        ElasticsearchServerless::API::Response.new(
          perform_request(method, path, params, payload, headers, request_opts)
        )
      end