From 15cf7e15a9c5342881f44f1fe4cd479b7f7d7e12 Mon Sep 17 00:00:00 2001 From: Adam Engesath Date: Thu, 18 Feb 2016 16:46:09 -0500 Subject: [PATCH] add support for min_doc_count in aggregations --- .gitignore | 1 + README.md | 7 +++++++ lib/searchkick/query.rb | 2 +- test/aggs_test.rb | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6247dee..1eedfae 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ tmp *.log .DS_Store .ruby-* +.idea/ diff --git a/README.md b/README.md index 159448b..7e61e35 100644 --- a/README.md +++ b/README.md @@ -624,6 +624,13 @@ Limit Product.search "apples", aggs: {store_id: {limit: 10}} ``` +Minimum Document Count + +```ruby +Product.search "apples", aggs: {store_id: {min_doc_count: 2}} +# Only return stores that have 2 or more hits +``` + Order ```ruby diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index 1d65bc9..69922ce 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -527,7 +527,7 @@ module Searchkick aggs.each do |field, agg_options| size = agg_options[:limit] ? agg_options[:limit] : 1_000 - shared_agg_options = agg_options.slice(:order) + shared_agg_options = agg_options.slice(:order, :min_doc_count) if agg_options[:ranges] payload[:aggs][field] = { diff --git a/test/aggs_test.rb b/test/aggs_test.rb index ab94b60..a264810 100644 --- a/test/aggs_test.rb +++ b/test/aggs_test.rb @@ -30,6 +30,10 @@ class AggsTest < Minitest::Test assert_equal ({1 => 1, 2 => 2}), store_agg({aggs: {store_id_new: {field: "store_id"}}}, "store_id_new") end + def test_min_doc_count + assert_equal ({2 => 2}), store_agg(aggs: {store_id: { min_doc_count: 2 }}) + end + def test_no_aggs assert_nil Product.search("*").aggs end -- libgit2 0.21.0