Commit 15cf7e15a9c5342881f44f1fe4cd479b7f7d7e12
1 parent
39209254
Exists in
master
and in
21 other branches
add support for min_doc_count in aggregations
Showing
4 changed files
with
13 additions
and
1 deletions
Show diff stats
.gitignore
README.md
@@ -624,6 +624,13 @@ Limit | @@ -624,6 +624,13 @@ Limit | ||
624 | Product.search "apples", aggs: {store_id: {limit: 10}} | 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 | Order | 634 | Order |
628 | 635 | ||
629 | ```ruby | 636 | ```ruby |
lib/searchkick/query.rb
@@ -527,7 +527,7 @@ module Searchkick | @@ -527,7 +527,7 @@ module Searchkick | ||
527 | 527 | ||
528 | aggs.each do |field, agg_options| | 528 | aggs.each do |field, agg_options| |
529 | size = agg_options[:limit] ? agg_options[:limit] : 1_000 | 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 | if agg_options[:ranges] | 532 | if agg_options[:ranges] |
533 | payload[:aggs][field] = { | 533 | payload[:aggs][field] = { |
test/aggs_test.rb
@@ -30,6 +30,10 @@ class AggsTest < Minitest::Test | @@ -30,6 +30,10 @@ class AggsTest < Minitest::Test | ||
30 | assert_equal ({1 => 1, 2 => 2}), store_agg({aggs: {store_id_new: {field: "store_id"}}}, "store_id_new") | 30 | assert_equal ({1 => 1, 2 => 2}), store_agg({aggs: {store_id_new: {field: "store_id"}}}, "store_id_new") |
31 | end | 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 | def test_no_aggs | 37 | def test_no_aggs |
34 | assert_nil Product.search("*").aggs | 38 | assert_nil Product.search("*").aggs |
35 | end | 39 | end |