Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Avg

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

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Avg.

Parameters:

  • name (String)

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

  • field (String)

    The field over which the average should be calculated.

  • missing (Float) (defaults to: nil)

    The value to use for the documents where field is missing. If no value is provided for missing these documents are ignored,



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

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

  @field = field
  @missing = missing
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



13
14
15
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/avg.rb', line 13

def field
  @field
end

#missingObject (readonly)

Returns the value of attribute missing.



13
14
15
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/avg.rb', line 13

def missing
  @missing
end

Instance Method Details

#aggsObject

Raises:



31
32
33
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/avg.rb', line 31

def aggs
  no_nested_aggregations('Avg')
end

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



36
37
38
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/avg.rb', line 36

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.



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

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