Commit a09b84389e6ac8120e37bc9f93fa789f5394e0a7

Authored by Andrew Kane
1 parent 690d93e2

Cleaned up search notifications

Showing 2 changed files with 11 additions and 17 deletions   Show diff stats
1 -## 4.1.2 (unreleased) 1 +## 4.2.0 (unreleased)
2 2
3 - Added safety check for multiple `Model.reindex` 3 - Added safety check for multiple `Model.reindex`
4 - Added `deep_paging` option 4 - Added `deep_paging` option
5 - Added request parameters to `curl` representation 5 - Added request parameters to `curl` representation
  6 +- Cleaned up search notifications
6 7
7 ## 4.1.1 (2019-11-19) 8 ## 4.1.1 (2019-11-19)
8 9
lib/searchkick/logging.rb
@@ -7,7 +7,8 @@ module Searchkick @@ -7,7 +7,8 @@ module Searchkick
7 name = searchkick_klass ? "#{searchkick_klass.name} Search" : "Search" 7 name = searchkick_klass ? "#{searchkick_klass.name} Search" : "Search"
8 event = { 8 event = {
9 name: name, 9 name: name,
10 - query: params 10 + query: params,
  11 + term: term
11 } 12 }
12 ActiveSupport::Notifications.instrument("search.searchkick", event) do 13 ActiveSupport::Notifications.instrument("search.searchkick", event) do
13 super 14 super
@@ -132,7 +133,8 @@ module Searchkick @@ -132,7 +133,8 @@ module Searchkick
132 def multi_search(searches) 133 def multi_search(searches)
133 event = { 134 event = {
134 name: "Multi Search", 135 name: "Multi Search",
135 - body: searches.flat_map { |q| [q.params.except(:body).to_json, q.body.to_json] }.map { |v| "#{v}\n" }.join 136 + body: searches.flat_map { |q| [q.params.except(:body).to_json, q.body.to_json] }.map { |v| "#{v}\n" }.join,
  137 + term: searches.first.term
136 } 138 }
137 ActiveSupport::Notifications.instrument("multi_search.searchkick", event) do 139 ActiveSupport::Notifications.instrument("multi_search.searchkick", event) do
138 super 140 super
@@ -162,17 +164,9 @@ module Searchkick @@ -162,17 +164,9 @@ module Searchkick
162 164
163 payload = event.payload 165 payload = event.payload
164 name = "#{payload[:name]} (#{event.duration.round(1)}ms)" 166 name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
165 - type = payload[:query][:type]  
166 - index = payload[:query][:index].is_a?(Array) ? payload[:query][:index].join(",") : payload[:query][:index]  
167 - request_params = payload[:query].except(:index, :type, :body)  
168 -  
169 - # no easy way to tell which host the client will use  
170 - host = Searchkick.client.transport.hosts.first  
171 - params = ["pretty"]  
172 - request_params.each do |k, v|  
173 - params << "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"  
174 - end  
175 - 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}'" 167 + message = {term: payload[:term]}
  168 +
  169 + debug " #{color(name, YELLOW, true)} #{message.to_json}"
176 end 170 end
177 171
178 def request(event) 172 def request(event)
@@ -191,10 +185,9 @@ module Searchkick @@ -191,10 +185,9 @@ module Searchkick
191 185
192 payload = event.payload 186 payload = event.payload
193 name = "#{payload[:name]} (#{event.duration.round(1)}ms)" 187 name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
  188 + message = {term: payload[:term]}
194 189
195 - # no easy way to tell which host the client will use  
196 - host = Searchkick.client.transport.hosts.first  
197 - debug " #{color(name, YELLOW, true)} curl #{host[:protocol]}://#{host[:host]}:#{host[:port]}/_msearch?pretty -H 'Content-Type: application/json' -d '#{payload[:body]}'" 190 + debug " #{color(name, YELLOW, true)} #{message.to_json}"
198 end 191 end
199 end 192 end
200 193