Aggregation

.aggregate([aggregations])

Groups and summarizes data from the graph. It allows you to perform calculations on vertex or edge properties. The following aggregation types are available:

Aggregation Types

.gripql.term(name, field, size)

Return top n terms and their counts for a field.

G.V().hasLabel("Person").aggregate(gripql.term("top-names", "name", 10))

Counts name occurences across Person vertices and returns the 10 most frequent name values.

.gripql.histogram(name, field, interval)

Return binned counts for a field.

G.V().hasLabel("Person").aggregate(gripql.histogram("age-hist", "age", 5))

Creates a histogram of age values with bins of width 5 across Person vertices.

.gripql.percentile(name, field, percents=[])

Return percentiles for a field.

G.V().hasLabel("Person").aggregate(gripql.percentile("age-percentiles", "age", [25,50,75]))

Calculates the 25th, 50th, and 75th percentiles for age values across Person vertices.

.gripql.field(“fields”, “$”)

Returns all of the fields found in the data structure. Use $ to get a listing of all fields found at the root level of the data property of vertices or edges.


gripql.type(name, field)

Returns the data type of requested field. For the python client, if field is not provided, it is copied from name.

Current returned types include NUMERIC, STRING and UNKNOWN. If a field is always null, or has multiple types, it will be returned as UNKNOWN.


.count()

Returns the total number of elements in the traversal.

Example:

G.query().V().hasLabel("Person").count()

This query returns the total number of vertices with the label “Person”.


.distinct([fields])

Filters the traversal to return only unique elements. If fields are provided, uniqueness is determined by the combination of values in those fields; otherwise, the _id is used.

Example:

G.query().V().hasLabel("Person").distinct(["name", "age"])

This query returns only unique “Person” vertices, where uniqueness is determined by the combination of “name” and “age” values.


.sort([fields])

Sort the output using the field values