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: 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.
-
#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) ⇒ Terms
constructor
A new instance of Terms.
-
#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) ⇒ Terms
Returns a new instance of Terms.
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
#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 |
#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.
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_h ⇒ Hash
Returns The Hash representation of the Aggregation
. Properly formatted for Elasticsearch.
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 |