Class: ElasticsearchDslBuilder::DSL::Search::Aggregations::Aggregation
- Inherits:
-
Object
- Object
- ElasticsearchDslBuilder::DSL::Search::Aggregations::Aggregation
- Defined in:
- lib/elasticsearch_dsl_builder/dsl/search/aggregation.rb
Overview
Base class for aggregation types
Direct Known Subclasses
Cardinality, Children, DateHistogram, DateRange, Filter, Filters, GeohashGrid, Nested, Range, ReverseNested, Stats, Sum, SumBucket, Terms
Instance Method Summary collapse
-
#aggregation(name, aggregation) ⇒ Object
Defines an aggregation nested in another one.
- #to_hash ⇒ Object
Instance Method Details
#aggregation(name, aggregation) ⇒ Object
Defines an aggregation nested in another one
15 16 17 18 19 20 21 22 23 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregation.rb', line 15 def aggregation(name, aggregation) name_valid = name.instance_of?(String) || name.instance_of?(Symbol) raise ArgumentError, 'name must be a String or Symbol' unless name_valid raise ArgumentError, 'aggregation must extend Aggregation' unless aggregation.is_a?(Aggregation) @aggregations ||= AggregationsCollection.new @aggregations[name.to_sym] = aggregation self end |
#to_hash ⇒ Object
25 26 27 28 29 30 |
# File 'lib/elasticsearch_dsl_builder/dsl/search/aggregation.rb', line 25 def to_hash hash = {} hash.update(@type => @aggregation.to_hash) if @aggregation hash.update(aggregations: @aggregations.to_hash) if @aggregations hash end |