pandagg.node.aggs.abstract module

pandagg.node.aggs.abstract.A(name: str, type_or_agg: Union[str, Dict[str, Dict[str, Any]], pandagg.node.aggs.abstract.AggClause, None] = None, **body) → pandagg.node.aggs.abstract.AggClause[source]

Accept multiple syntaxes, return a AggNode instance.

Parameters:
  • name – aggregation clause name
  • type_or_agg
  • body
Returns:

AggNode

class pandagg.node.aggs.abstract.AggClause(meta: Optional[Dict[str, Any]] = None, identifier: Optional[str] = None, **body)[source]

Bases: pandagg.node._node.Node

Wrapper around elasticsearch aggregation concept. https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-aggregations.html

Each aggregation can be seen both a Node that can be encapsulated in a parent agg.

Define a method to build aggregation request.

classmethod extract_bucket_value(response: Union[pandagg.types.BucketsWrapperDict, Dict[str, Any]], value_as_dict: bool = False) → Any[source]
extract_buckets(response_value: Union[pandagg.types.BucketsWrapperDict, Dict[str, Any]]) → Iterator[Tuple[Union[None, str, float, Dict[str, Union[str, float, None]]], Dict[str, Any]]][source]
is_convertible_to_composite_source() → bool[source]
line_repr(depth: int, **kwargs) → Tuple[str, str][source]

Control how node is displayed in tree representation. First returned string is how node is represented on left, second string is how node is represented on right.

MyTree ├── one OneEnd │ └── two twoEnd └── three threeEnd

to_dict() → Dict[str, Dict[str, Any]][source]

ElasticSearch aggregation queries follow this formatting:

{
    "<aggregation_name>" : {
        "<aggregation_type>" : {
            <aggregation_body>
        }
        [,"meta" : {  [<meta_data_body>] } ]?
    }
}

to_dict() returns the following part (without aggregation name):

{
    "<aggregation_type>" : {
        <aggregation_body>
    }
    [,"meta" : {  [<meta_data_body>] } ]?
}
classmethod valid_on_field_type(field_type: str) → bool[source]
class pandagg.node.aggs.abstract.BucketAggClause(**body)[source]

Bases: pandagg.node.aggs.abstract.AggClause

Bucket aggregation have special abilities: they can encapsulate other aggregations as children. Each time, the extracted value is a ‘doc_count’.

Provide methods: - to build aggregation request (with children aggregations) - to to extract buckets from raw response - to build query to filter documents belonging to that bucket

Note: the aggs attribute’s only purpose is for children initiation with the following syntax: >>> from pandagg.aggs import Terms, Avg >>> agg = Terms( >>> field=’some_path’, >>> aggs={ >>> ‘avg_agg’: Avg(field=’some_other_path’) >>> } >>> )

extract_buckets(response_value: Union[pandagg.types.BucketsWrapperDict, Dict[str, Any]]) → Iterator[Tuple[Union[None, str, float, Dict[str, Union[str, float, None]]], Dict[str, Any]]][source]
class pandagg.node.aggs.abstract.FieldOrScriptMetricAgg(field: Optional[str] = None, script: Optional[pandagg.types.Script] = None, **body)[source]

Bases: pandagg.node.aggs.abstract.MetricAgg

Metric aggregation based on single field.

class pandagg.node.aggs.abstract.MetricAgg(meta: Optional[Dict[str, Any]] = None, identifier: Optional[str] = None, **body)[source]

Bases: pandagg.node.aggs.abstract.AggClause

Metric aggregation are aggregations providing a single bucket, with value attributes to be extracted.

extract_buckets(response_value: Union[pandagg.types.BucketsWrapperDict, Dict[str, Any]]) → Iterator[Tuple[Union[None, str, float, Dict[str, Union[str, float, None]]], Dict[str, Any]]][source]
class pandagg.node.aggs.abstract.MultipleBucketAgg(keyed: bool = False, key_as_string: bool = False, **body)[source]

Bases: pandagg.node.aggs.abstract.BucketAggClause

IMPLICIT_KEYED = False
extract_buckets(response_value: Union[pandagg.types.BucketsWrapperDict, Dict[str, Any]]) → Iterator[Tuple[Union[None, str, float, Dict[str, Union[str, float, None]]], Dict[str, Any]]][source]
class pandagg.node.aggs.abstract.Pipeline(buckets_path: str, gap_policy: Optional[typing_extensions.Literal['skip', 'insert_zeros', 'keep_values'][skip, insert_zeros, keep_values]] = None, **body)[source]

Bases: pandagg.node.aggs.abstract.UniqueBucketAgg

class pandagg.node.aggs.abstract.Root(meta: Optional[Dict[str, Any]] = None, identifier: Optional[str] = None, **body)[source]

Bases: pandagg.node.aggs.abstract.AggClause

Not a real aggregation. Just the initial empty dict (used as lighttree.Tree root).

KEY = '_root'
classmethod extract_bucket_value(response: Union[pandagg.types.BucketsWrapperDict, Dict[str, Any]], value_as_dict: bool = False) → Any[source]
extract_buckets(response_value: Union[pandagg.types.BucketsWrapperDict, Dict[str, Any]]) → Iterator[Tuple[Union[None, str, float, Dict[str, Union[str, float, None]]], Dict[str, Any]]][source]
line_repr(depth: int, **kwargs) → Tuple[str, str][source]

Control how node is displayed in tree representation. First returned string is how node is represented on left, second string is how node is represented on right.

MyTree ├── one OneEnd │ └── two twoEnd └── three threeEnd

class pandagg.node.aggs.abstract.ScriptPipeline(script: pandagg.types.Script, buckets_path: str, gap_policy: Optional[typing_extensions.Literal['skip', 'insert_zeros', 'keep_values'][skip, insert_zeros, keep_values]] = None, **body)[source]

Bases: pandagg.node.aggs.abstract.Pipeline

VALUE_ATTRS = ['value']
class pandagg.node.aggs.abstract.UniqueBucketAgg(**body)[source]

Bases: pandagg.node.aggs.abstract.BucketAggClause

Aggregations providing a single bucket.

extract_buckets(response_value: Union[pandagg.types.BucketsWrapperDict, Dict[str, Any]]) → Iterator[Tuple[Union[None, str, float, Dict[str, Union[str, float, None]]], Dict[str, Any]]][source]