Class: JayAPI::Elasticsearch::QueryBuilder::Aggregations::Terms
- Inherits:
-
Aggregation
- Object
- Aggregation
- JayAPI::Elasticsearch::QueryBuilder::Aggregations::Terms
- 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:
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#missing ⇒ Object
readonly
Returns the value of attribute missing.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from Aggregation
Instance Method Summary collapse
-
#clone ⇒ self
A copy of the receiver.
-
#initialize(name, field: nil, script: nil, size: nil, order: nil, missing: nil) ⇒ Terms
constructor
rubocop:disable Metrics/ParameterLists -- Constraint by Elasticsearch's design :reek:LongParameterList -- Constraint by Elasticsearch's design.
-
#to_h ⇒ Hash
The Hash representation of the
Aggregation.
Methods inherited from Aggregation
Constructor Details
#initialize(name, field: nil, script: nil, size: nil, order: nil, missing: nil) ⇒ Terms
rubocop:disable Metrics/ParameterLists -- Constraint by Elasticsearch's design :reek:LongParameterList -- Constraint by Elasticsearch's design
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 40 def initialize(name, field: nil, script: nil, size: nil, order: nil, missing: 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 @missing = missing end |
Instance Attribute Details
#field ⇒ Object (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 |
#missing ⇒ Object (readonly)
Returns the value of attribute missing.
17 18 19 |
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 17 def missing @missing end |
#order ⇒ Object (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 |
#script ⇒ Object (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 |
#size ⇒ Object (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
#clone ⇒ self
Returns A copy of the receiver.
57 58 59 60 61 |
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 57 def clone self.class.new( name, field: field, script: script, size: size, order: order&.deep_dup, missing: missing ).tap { |copy| copy.aggregations = aggregations.clone } end |
#to_h ⇒ Hash
Returns The Hash representation of the Aggregation.
Properly formatted for Elasticsearch.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jay_api/elasticsearch/query_builder/aggregations/terms.rb', line 65 def to_h super do { terms: { field: field, size: size, script: script&.to_h, order: order, missing: missing }.compact } end end |