Module: ElasticGraph::GraphQL::Aggregation::Key
- Defined in:
- lib/elastic_graph/graphql/aggregation/key.rb
Defined Under Namespace
Classes: AggregatedValue
Constant Summary collapse
- DELIMITER =
The datastore only gives us an “aggregation key” (or name) to tie response values back to the part of request it came from. We use this delimiter to encode and decode aggregation keys.
":"
Class Method Summary collapse
- .encode(parts) ⇒ Object
-
.extract_aggregation_name_from(agg_name_or_key) ⇒ Object
Extracts an aggregation name from a string that could either already be an aggregation name, or could be an encoded key.
-
.missing_value_bucket_key(base_key) ⇒ Object
Encodes the key used for a ‘missing` aggregation used to provide a bucket for documents that are missing a value for the field being grouped on.
- .verify_no_delimiter_in(*parts) ⇒ Object
Class Method Details
.encode(parts) ⇒ Object
73 74 75 |
# File 'lib/elastic_graph/graphql/aggregation/key.rb', line 73 def self.encode(parts) parts.join(DELIMITER) end |
.extract_aggregation_name_from(agg_name_or_key) ⇒ Object
Extracts an aggregation name from a string that could either already be an aggregation name, or could be an encoded key. We need this for dealing with the multiple forms that aggregation responses take:
-
When we use ‘grouped_by`, we run a composite aggregation that has the aggregation name, and that shows up as a key directly under `aggregations` in the datastore response.
-
For aggregations with no ‘grouped_by`, we encode the aggregation name in the key, and the keys directly under `aggregations` in the datastore response will take a from like: `[agg_name]::[function]`.
It’s also possible for these two forms to be mixed under ‘aggregations` on a datastore response, where some hash keys are in one form and some are in the other form. This can happen when we run multiple aggregations (some with `grouped_by`, some without) in the same query.
69 70 71 |
# File 'lib/elastic_graph/graphql/aggregation/key.rb', line 69 def self.extract_aggregation_name_from(agg_name_or_key) agg_name_or_key.split(DELIMITER, 2).first || agg_name_or_key end |
.missing_value_bucket_key(base_key) ⇒ Object
Encodes the key used for a ‘missing` aggregation used to provide a bucket for documents that are missing a value for the field being grouped on.
53 54 55 |
# File 'lib/elastic_graph/graphql/aggregation/key.rb', line 53 def self.missing_value_bucket_key(base_key) Key.encode([base_key, "m"]) end |
.verify_no_delimiter_in(*parts) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/elastic_graph/graphql/aggregation/key.rb', line 77 def self.verify_no_delimiter_in(*parts) parts.each do |part| if part.to_s.include?(DELIMITER) raise InvalidArgumentValueError, %("#{part}" contains delimiter: "#{DELIMITER}") end end end |