Nodes are filtered based on functions applied to the node’s outgoing edges.
So far the queries have only applied a filter to the top level nodes, but filters can be applied to any node in the query.
Note the syntax difference between filtering at the root of a query and filtering on internal blocks.
There are many functions for filtering, some of them are
allOfTerms(edge_name, "term1 ... termN")
: matches nodes with an outgoing
string
edge edge_name
where the string contains all listed terms.
anyOfTerms(edge_name, "term1 ... termN")
: As with allOfTerms
, but matches
at least one term.
The equalities and inequalities can be applied to edges of types: int
,
float
, string
and date
eq(edge_name, value)
: equal toge(edge_name, value)
: greater than or equal tole(edge_name, value)
: less than or equal togt(edge_name, value)
: greater thanlt(edge_name, value)
: less thanThere’s also regular expressions, full text search and geo search, but those are bigger topics that’ll have their own section in the tutorial
Functions can only be applied to predicates that have been indexed except the
case when comparison functions (eq
, ge
, gt
, le
, lt
) are used in
filter - that’s part of the lesson about schema.
{
michaels_friends_filter(func: allofterms(name@., "Michael")) {
name
age
friend @filter(ge(age, 27)) {
name@.
age
}
}
}
2.6 Functions and filtering