Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Composite

Inherits:
Aggregation
  • Object
show all
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

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Methods inherited from Aggregation

#aggs

Constructor Details

#initialize(name, size: nil) {|The| ... } ⇒ Composite

Returns a new instance of Composite.

Parameters:

  • name (String)

    The name of the composite aggregation.

  • size (Integer) (defaults to: nil)

    The number of composite buckets to return.

Yield Parameters:

Raises:



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

#sizeObject (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

#cloneself

Returns A copy of the receiver. Sources and nested aggregations are also cloned.

Returns:

  • (self)

    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_hHash

Returns The Hash representation of the Aggregation. Properly formatted for Elasticsearch.

Returns:

  • (Hash)

    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