Commit 84b5d7bba38bc587815e0387947357d7e950acdd

Authored by Andrew Kane
1 parent fee4f531

Fixed order option for aggregations

Showing 1 changed file with 7 additions and 9 deletions   Show diff stats
lib/searchkick/query.rb
... ... @@ -351,30 +351,28 @@ module Searchkick
351 351  
352 352 aggs.each do |field, agg_options|
353 353 size = agg_options[:limit] ? agg_options[:limit] : 100_000
  354 + shared_agg_options = agg_options.slice(:order)
354 355  
355 356 if agg_options[:ranges]
356 357 payload[:aggs][field] = {
357 358 range: {
358 359 field: agg_options[:field] || field,
359   - ranges: agg_options[:ranges],
360   - order: agg_options[:order]
361   - }
  360 + ranges: agg_options[:ranges]
  361 + }.merge(shared_agg_options)
362 362 }
363 363 elsif agg_options[:date_ranges]
364 364 payload[:aggs][field] = {
365 365 date_range: {
366 366 field: agg_options[:field] || field,
367   - ranges: agg_options[:date_ranges],
368   - order: agg_options[:order]
369   - }
  367 + ranges: agg_options[:date_ranges]
  368 + }.merge(shared_agg_options)
370 369 }
371 370 else
372 371 payload[:aggs][field] = {
373 372 terms: {
374 373 field: agg_options[:field] || field,
375   - size: size,
376   - order: agg_options[:order]
377   - }
  374 + size: size
  375 + }.merge(shared_agg_options)
378 376 }
379 377 end
380 378  
... ...