Class: ElasticGraph::GraphQL::Aggregation::NestedSubAggregation

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/graphql/aggregation/nested_sub_aggregation.rb

Overview

Represents a sub-aggregation on a ‘nested` field. For the relevant Elasticsearch docs, see: www.elastic.co/guide/en/elasticsearch/reference/8.10/search-aggregations-bucket-nested-aggregation.html

Instance Method Summary collapse

Instance Method Details

#build_agg_hash(filter_interpreter, parent_queries:) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/elastic_graph/graphql/aggregation/nested_sub_aggregation.rb', line 28

def build_agg_hash(filter_interpreter, parent_queries:)
  detail = query.build_agg_detail(filter_interpreter, field_path: nested_path, parent_queries: parent_queries)
  return {} if detail.nil?

  parent_query_names = parent_queries.map(&:name)
  {
    Key.encode(parent_query_names + [nested_path_key]) => {
      "nested" => {"path" => FieldPathEncoder.encode(nested_path.filter_map(&:name_in_index))},
      "aggs" => detail.clauses,
      "meta" => detail.meta.merge({
        "size" => query.paginator.desired_page_size,
        "adapter" => query.grouping_adapter.meta_name
      })
    }.compact
  }
end

#nested_path_keyObject

The nested path in the GraphQL query from the parent aggregation to this-subaggregation, encoded for use as a hash key.

This key will be unique in the scope of the parent aggregation query, and thus suitable as a key in a sub-aggregations hash.



24
25
26
# File 'lib/elastic_graph/graphql/aggregation/nested_sub_aggregation.rb', line 24

def nested_path_key
  @nested_path_key ||= FieldPathEncoder.encode(nested_path.map(&:name_in_graphql_query))
end