Class: ElasticGraph::GraphQL::Aggregation::Resolvers::CountDetail

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

Overview

Resolves the detailed ‘count` sub-fields of a sub-aggregation. It’s an object because the count we get from the datastore may not be accurate and we have multiple fields we expose to give the client control over how much detail they want.

Note: for now our resolver logic only uses the bucket fields returned to us by the datastore, but I believe we may have some opportunities to provide more accurate responses to these when custom shard routing and/or index rollover are in use. For example, when grouping on the custom shard routing field, we know that no term bucket will have data from more than one shard. The datastore isn’t aware of our custom shard routing logic, though, and can’t account for that in what it returns, so it may indicate a potential error upper bound where we can deduce there is none.

Instance Method Summary collapse

Instance Method Details

#approximate_valueObject

The (potentially approximate) ‘doc_count` returned by the datastore for a bucket.



27
28
29
# File 'lib/elastic_graph/graphql/aggregation/resolvers/count_detail.rb', line 27

def approximate_value
  @approximate_value ||= bucket.fetch("doc_count")
end

#exact_valueObject

The ‘doc_count`, if we know it was exact. (Otherwise, returns `nil`).



32
33
34
# File 'lib/elastic_graph/graphql/aggregation/resolvers/count_detail.rb', line 32

def exact_value
  approximate_value if approximate_value == upper_bound
end

#upper_boundObject

The upper bound on how large the doc count could be.



37
38
39
# File 'lib/elastic_graph/graphql/aggregation/resolvers/count_detail.rb', line 37

def upper_bound
  @upper_bound ||= bucket.fetch("doc_count_error_upper_bound") + approximate_value
end