Module: ElasticGraph::GraphQL::Aggregation::CompositeGroupingAdapter

Defined in:
lib/elastic_graph/graphql/aggregation/composite_grouping_adapter.rb

Overview

Grouping adapter that uses a ‘composite` aggregation.

For now, only used for the outermost “root” aggregations but may be used for sub-aggregations in the future.

Class Method Summary collapse

Class Method Details

.grouping_detail_for(query) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/elastic_graph/graphql/aggregation/composite_grouping_adapter.rb', line 21

def grouping_detail_for(query)
  sources = build_sources(query)

  inner_clauses = yield
  inner_clauses = nil if inner_clauses.empty?

  return AggregationDetail.new(inner_clauses, {}) if sources.empty?

  clauses = {
    query.name => {
      "composite" => {
        "size" => query.paginator.requested_page_size,
        "sources" => sources,
        "after" => composite_after(query)
      }.compact,
      "aggs" => inner_clauses
    }.compact
  }

  AggregationDetail.new(clauses, {"buckets_path" => [query.name]})
end

.meta_nameObject



17
18
19
# File 'lib/elastic_graph/graphql/aggregation/composite_grouping_adapter.rb', line 17

def meta_name
  "comp"
end

.prepare_response_buckets(sub_agg, buckets_path, meta) ⇒ Object



43
44
45
46
47
# File 'lib/elastic_graph/graphql/aggregation/composite_grouping_adapter.rb', line 43

def prepare_response_buckets(sub_agg, buckets_path, meta)
  sub_agg.dig(*buckets_path).fetch("buckets").map do |bucket|
    bucket.merge({"doc_count_error_upper_bound" => 0})
  end
end