diff --git a/CHANGELOG.md b/CHANGELOG.md index cbdf476..4a43418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Added safety check for multiple `Model.reindex` - Added `deep_paging` option +- Added request parameters to `curl` representation ## 4.1.1 (2019-11-19) diff --git a/lib/searchkick/logging.rb b/lib/searchkick/logging.rb index 50d6801..44bb1d8 100644 --- a/lib/searchkick/logging.rb +++ b/lib/searchkick/logging.rb @@ -164,11 +164,14 @@ module Searchkick name = "#{payload[:name]} (#{event.duration.round(1)}ms)" type = payload[:query][:type] index = payload[:query][:index].is_a?(Array) ? payload[:query][:index].join(",") : payload[:query][:index] + request_params = payload[:query].except(:index, :type, :body) # no easy way to tell which host the client will use host = Searchkick.client.transport.hosts.first params = ["pretty"] - params << "scroll=#{payload[:query][:scroll]}" if payload[:query][:scroll] + request_params.each do |k, v| + params << "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" + end debug " #{color(name, YELLOW, true)} curl #{host[:protocol]}://#{host[:host]}:#{host[:port]}/#{CGI.escape(index)}#{type ? "/#{type.map { |t| CGI.escape(t) }.join(',')}" : ''}/_search?#{params.join('&')} -H 'Content-Type: application/json' -d '#{payload[:query][:body].to_json}'" end diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 9fd5d86..8238d70 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -106,12 +106,15 @@ module Searchkick query = params type = query[:type] index = query[:index].is_a?(Array) ? query[:index].join(",") : query[:index] + request_params = query.except(:index, :type, :body) # no easy way to tell which host the client will use host = Searchkick.client.transport.hosts.first credentials = host[:user] || host[:password] ? "#{host[:user]}:#{host[:password]}@" : nil params = ["pretty"] - params << "scroll=#{options[:scroll]}" if options[:scroll] + request_params.each do |k, v| + params << "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" + end "curl #{host[:protocol]}://#{credentials}#{host[:host]}:#{host[:port]}/#{CGI.escape(index)}#{type ? "/#{type.map { |t| CGI.escape(t) }.join(',')}" : ''}/_search?#{params.join('&')} -H 'Content-Type: application/json' -d '#{query[:body].to_json}'" end -- libgit2 0.21.0