Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Sum

Inherits:
Aggregation
  • Object
show all
Defined in:
lib/jay_api/elasticsearch/query_builder/aggregations/sum.rb

Overview

Represents a sum aggregation in Elasticsearch. Information on this type of aggregation can be found here: www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Constructor Details

#initialize(name, field:, missing: nil) ⇒ Sum

Returns a new instance of Sum.

Parameters:

  • name (String)

    The name used by Elasticsearch to identify each of the aggregations.

  • field (String)

    The field whose values should be added-up

  • missing (Numeric) (defaults to: nil)

    The value to use when the field doesn’t have a value. The type of the parameter depends on the type of the field in Elasticsearch.



23
24
25
26
27
28
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sum.rb', line 23

def initialize(name, field:, missing: nil)
  super(name)

  @field = field
  @missing = missing
end

Instance Attribute Details

#fieldObject (readonly)

TODO: Add script support to the aggregation



15
16
17
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sum.rb', line 15

def field
  @field
end

#missingObject (readonly)

TODO: Add script support to the aggregation



15
16
17
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sum.rb', line 15

def missing
  @missing
end

Instance Method Details

#aggsObject

Raises:



32
33
34
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sum.rb', line 32

def aggs
  no_nested_aggregations('Sum')
end

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



37
38
39
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sum.rb', line 37

def clone
  self.class.new(name, field: field, missing: missing)
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.



43
44
45
46
47
48
49
50
51
52
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/sum.rb', line 43

def to_h
  super do
    {
      sum: {
        field: field,
        missing: missing
      }.compact
    }
  end
end