Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Cardinality

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

Overview

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

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Constructor Details

#initialize(name, field:) ⇒ Cardinality

Returns a new instance of Cardinality.

Parameters:

  • name (String)

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

  • field (String)

    The field whose cardinality (number of unique values) should be calculated.



19
20
21
22
23
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/cardinality.rb', line 19

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

  @field = field
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



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

def field
  @field
end

Instance Method Details

#aggsObject

Raises:



28
29
30
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/cardinality.rb', line 28

def aggs
  no_nested_aggregations('Cardinality')
end

#cloneself

Returns A copy of the receiver.

Returns:

  • (self)

    A copy of the receiver.



33
34
35
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/cardinality.rb', line 33

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



39
40
41
42
43
44
45
46
47
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/cardinality.rb', line 39

def to_h
  super do
    {
      cardinality: {
        field: field
      }
    }
  end
end