Class: ElasticGraph::GraphQL::Aggregation::DateHistogramGrouping
- Inherits:
-
Object
- Object
- ElasticGraph::GraphQL::Aggregation::DateHistogramGrouping
- Defined in:
- lib/elastic_graph/graphql/aggregation/date_histogram_grouping.rb
Overview
Represents a grouping of a timestamp field into a date histogram. For the relevant Elasticsearch docs, see: www.elastic.co/guide/en/elasticsearch/reference/7.12/search-aggregations-bucket-datehistogram-aggregation.html www.elastic.co/guide/en/elasticsearch/reference/7.12/search-aggregations-bucket-composite-aggregation.html#_date_histogram
Constant Summary collapse
- INNER_META =
{ # On a date histogram aggregation, the `key` is formatted as a number (milliseconds since epoch). We # need it formatted as a string, which `key_as_string` provides. "key_path" => ["key_as_string"], # Date histogram aggregations do not have any doc count error. Our resolver is generic and expects # there to always be a `doc_count_error_upper_bound`. So we want to tell it to merge an error of `0` # into each bucket. "merge_into_bucket" => {"doc_count_error_upper_bound" => 0} }
Instance Method Summary collapse
- #composite_clause(grouping_options: {}) ⇒ Object
- #encoded_index_field_path ⇒ Object
- #inner_meta ⇒ Object
- #key ⇒ Object
- #non_composite_clause_for(query) ⇒ Object
Instance Method Details
#composite_clause(grouping_options: {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/elastic_graph/graphql/aggregation/date_histogram_grouping.rb', line 29 def composite_clause(grouping_options: {}) = INTERVAL_OPTIONS_BY_NAME.fetch(interval) do raise ArgumentError, "#{interval.inspect} is an unsupported interval. Valid values: #{INTERVAL_OPTIONS_BY_NAME.keys.inspect}." end inner_hash = .merge().merge({ "field" => encoded_index_field_path, "format" => DATASTORE_DATE_TIME_FORMAT, "offset" => offset, "time_zone" => time_zone }.compact) {"date_histogram" => inner_hash} end |
#encoded_index_field_path ⇒ Object
25 26 27 |
# File 'lib/elastic_graph/graphql/aggregation/date_histogram_grouping.rb', line 25 def encoded_index_field_path @encoded_index_field_path ||= FieldPathEncoder.join(field_path.filter_map(&:name_in_index)) end |
#inner_meta ⇒ Object
52 53 54 |
# File 'lib/elastic_graph/graphql/aggregation/date_histogram_grouping.rb', line 52 def INNER_META end |
#key ⇒ Object
21 22 23 |
# File 'lib/elastic_graph/graphql/aggregation/date_histogram_grouping.rb', line 21 def key @key ||= FieldPathEncoder.encode(field_path.map(&:name_in_graphql_query)) end |
#non_composite_clause_for(query) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/elastic_graph/graphql/aggregation/date_histogram_grouping.rb', line 44 def non_composite_clause_for(query) # `min_doc_count: 1` is important so we don't have excess buckets when there is a large gap # between document dates. For example, if you group on a field at the year truncation unit, and # a one-off rogue document has an incorrect timestamp for hundreds of years ago, you'll wind # up with a bucket for each intervening year. `min_doc_count: 1` excludes those empty buckets. composite_clause(grouping_options: {"min_doc_count" => 1}) end |