Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ def method_missing(name, *args, &block)
#
def aggregation(*args, &block)
@aggregations ||= AggregationsCollection.new
@aggregations.update args.first => Aggregation.new(*args, &block)

if block
@aggregations.update args.first => Aggregation.new(*args, &block)
else
name = args.shift
@aggregations.update name => args.shift
end
self
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ class ::Elasticsearch::DSL::Search::Aggregations::Dummy

assert_equal 'foo', subject.to_hash[:aggregations][:inner][:dummy][:field]
end

should "add a nested aggregation instance" do
nested = Elasticsearch::DSL::Search::Aggregation.new do
dummy field: 'foo'
end
subject.aggregation :inner, nested

assert !subject.aggregations.empty?, "#{subject.aggregations.inspect} is empty"

assert_instance_of Elasticsearch::DSL::Search::Aggregation, subject.aggregations[:inner]
assert_equal({ dummy: { field: 'foo' } }, subject.aggregations[:inner].to_hash)

assert_equal 'foo', subject.to_hash[:aggregations][:inner][:dummy][:field]
end
end
end
end
Expand Down