Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Composite
- Inherits:
-
Aggregation
- Object
- Aggregation
- JayAPI::Elasticsearch::QueryBuilder::Aggregations::Composite
- Defined in:
- lib/jay_api/elasticsearch/query_builder/aggregations/composite.rb
Overview
Represents a Composite aggregation in Elasticsearch. For more information about this type of aggregation:
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from Aggregation
Instance Method Summary collapse
-
#clone ⇒ self
A copy of the receiver.
-
#initialize(name, size: nil) {|The| ... } ⇒ Composite
constructor
A new instance of Composite.
-
#to_h ⇒ Hash
The Hash representation of the
Aggregation
.
Methods inherited from Aggregation
Constructor Details
#initialize(name, size: nil) {|The| ... } ⇒ Composite
Returns a new instance of Composite.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/composite.rb', line 28 def initialize(name, size: nil, &block) unless block raise(::JayAPI::Elasticsearch::QueryBuilder::Aggregations::Errors::AggregationsError, "The #{self.class.name.demodulize} aggregation must be initialized with a block") end super(name) @size = size block.call(sources) end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
18 19 20 |
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/composite.rb', line 18 def size @size end |
Instance Method Details
#clone ⇒ self
Returns A copy of the receiver. Sources and nested aggregations are also cloned.
41 42 43 44 45 46 47 48 49 |
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/composite.rb', line 41 def clone # rubocop:disable Lint/EmptyBlock (The sources will be assigned later) copy = self.class.new(name, size: size) {} # rubocop:enable Lint/EmptyBlock copy.aggregations = aggregations.clone copy.sources = sources.clone copy end |
#to_h ⇒ Hash
Returns The Hash representation of the Aggregation
. Properly formatted for Elasticsearch.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/composite.rb', line 53 def to_h super do { composite: { sources: sources.to_a, size: size }.compact } end end |