Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Terms

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

Overview

Represents a terms aggregation in Elasticsearch. Information about this type of aggregation can be found in: www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

Instance Attribute Summary collapse

Attributes inherited from Aggregation

#name

Instance Method Summary collapse

Methods inherited from Aggregation

#aggs

Constructor Details

#initialize(name, field: nil, script: nil, size: nil, order: nil) ⇒ Terms

Returns a new instance of Terms.

Raises:

  • (ArgumentError)

    If neither a field nor a script are given or if both of them are given. Only one should be present.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 35

def initialize(name, field: nil, script: nil, size: nil, order: nil)
  if (field.present? && script.present?) || (field.blank? && script.blank?)
    raise ArgumentError, "Either 'field' or 'script' must be provided"
  end

  super(name)

  @field = field
  @script = script
  @size = size
  @order = order
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



17
18
19
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 17

def field
  @field
end

#orderObject (readonly)

Returns the value of attribute order.



17
18
19
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 17

def order
  @order
end

#scriptObject (readonly)

Returns the value of attribute script.



17
18
19
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 17

def script
  @script
end

#sizeObject (readonly)

Returns the value of attribute size.



17
18
19
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 17

def size
  @size
end

Instance Method Details

#cloneself



49
50
51
52
53
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 49

def clone
  self.class.new(name, field: field, script: script, size: size, order: order&.deep_dup).tap do |copy|
    copy.aggregations = aggregations.clone
  end
end

#to_hHash



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 57

def to_h
  super do
    {
      terms: {
        field: field,
        size: size,
        script: script&.to_h,
        order: order
      }.compact
    }
  end
end