Skip to content

Commit b36677e

Browse files
tmaierkarmi
authored andcommitted
1 parent 372fcec commit b36677e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Elasticsearch
2+
module DSL
3+
module Search
4+
module Aggregations
5+
6+
# A multi-bucket aggregation which returns the collection of terms and their document counts
7+
#
8+
# @example Passing the options as a Hash
9+
#
10+
# aggregation :tags do
11+
# missing field: 'tags'
12+
# end
13+
#
14+
# @example Passing the options as a block
15+
#
16+
# search do
17+
# aggregation :tags do
18+
# missing do
19+
# field 'tags'
20+
# end
21+
# end
22+
# end
23+
#
24+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/master/search-aggregations-bucket-missing-aggregation.html
25+
#
26+
class Missing
27+
include BaseAggregationComponent
28+
29+
option_method :field
30+
end
31+
32+
end
33+
end
34+
end
35+
end
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'test_helper'
2+
3+
module Elasticsearch
4+
module Test
5+
module Aggregations
6+
class RangeTest < ::Test::Unit::TestCase
7+
include Elasticsearch::DSL::Search::Aggregations
8+
9+
context "Missing aggregation" do
10+
subject { Missing.new }
11+
12+
should "be converted to a Hash" do
13+
assert_equal({ missing: {} }, subject.to_hash)
14+
end
15+
16+
should "take a Hash" do
17+
subject = Missing.new( { field: 'test' } )
18+
assert_equal({ missing: { field: "test" } }, subject.to_hash)
19+
end
20+
21+
should "have option methods" do
22+
subject.field 'foo'
23+
24+
assert_equal %w[ field ], subject.to_hash[:missing].keys.map(&:to_s).sort
25+
assert_equal 'foo', subject.to_hash[:missing][:field]
26+
end
27+
28+
should "take a block" do
29+
subject = Missing.new do
30+
field 'bar'
31+
end
32+
33+
assert_equal({missing: { field: 'bar' } }, subject.to_hash)
34+
end
35+
end
36+
end
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)