Commit 8dcbc68ba5d894cd5bdf85bf1e57c7a105bb5685

Authored by Andrew Kane
2 parents 39209254 15cf7e15

Merge pull request #635 from aengesath/master

Add Support for min_doc_count Filter in Aggregations Query with Tests
.gitignore
... ... @@ -18,3 +18,4 @@ tmp
18 18 *.log
19 19 .DS_Store
20 20 .ruby-*
  21 +.idea/
... ...
README.md
... ... @@ -624,6 +624,13 @@ Limit
624 624 Product.search "apples", aggs: {store_id: {limit: 10}}
625 625 ```
626 626  
  627 +Minimum Document Count
  628 +
  629 +```ruby
  630 +Product.search "apples", aggs: {store_id: {min_doc_count: 2}}
  631 +# Only return stores that have 2 or more hits
  632 +```
  633 +
627 634 Order
628 635  
629 636 ```ruby
... ...
lib/searchkick/query.rb
... ... @@ -527,7 +527,7 @@ module Searchkick
527 527  
528 528 aggs.each do |field, agg_options|
529 529 size = agg_options[:limit] ? agg_options[:limit] : 1_000
530   - shared_agg_options = agg_options.slice(:order)
  530 + shared_agg_options = agg_options.slice(:order, :min_doc_count)
531 531  
532 532 if agg_options[:ranges]
533 533 payload[:aggs][field] = {
... ...
test/aggs_test.rb
... ... @@ -30,6 +30,10 @@ class AggsTest < Minitest::Test
30 30 assert_equal ({1 => 1, 2 => 2}), store_agg({aggs: {store_id_new: {field: "store_id"}}}, "store_id_new")
31 31 end
32 32  
  33 + def test_min_doc_count
  34 + assert_equal ({2 => 2}), store_agg(aggs: {store_id: { min_doc_count: 2 }})
  35 + end
  36 +
33 37 def test_no_aggs
34 38 assert_nil Product.search("*").aggs
35 39 end
... ...