Skip to content

Commit 36870cc

Browse files
committed
[API] Generator: body for bulk, msearch and msearch_template is specific
1 parent 2a4fc7b commit 36870cc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

elasticsearch-api/utils/thor/templates/method.erb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,20 @@ module Elasticsearch
5353
<%- else -%>
5454
<%= ' '*(@namespace_depth+4) %>params = {}
5555
<%- end -%>
56-
<%= ' '*(@namespace_depth+4) %>body = <%= @spec['body'].nil? ? 'nil' : 'arguments[:body]' %>
5756
<%# Perform request %>
57+
<%= ' '*(@namespace_depth+4) %>body = <%= @spec['body'].nil? ? 'nil' : 'arguments[:body]' %>
5858
<% if ['bulk', 'msearch', 'msearch_template'].include? @method_name %>
59-
<%= ' '*(@namespace_depth+3) %> perform_request(method, path, params, body, {"Content-Type" => "application/x-ndjson"}).body
59+
if body.is_a? Array
60+
payload = Utils.__bulkify(body)
61+
else
62+
payload = body
63+
end
64+
65+
<%= ' '*(@namespace_depth+3) %> perform_request(method, path, params, payload, {"Content-Type" => "application/x-ndjson"}).body
6066
<% else %>
6167
<%= ' '*(@namespace_depth+3) %>perform_request(method, path, params, body).body
6268
<% end %>
6369
<%= ' '*(@namespace_depth+3) %>end
64-
6570
<%# Method, path, params, body -%>
6671
6772
<%= ' '*(@namespace_depth+3) %># Register this action with its valid params when the module is loaded.

0 commit comments

Comments
 (0)