# How Dgraph Search Works

Given what you’ve seen so far, you’ve probably already understood this, but it’s worth going over.

The graphs in Dgraph can be huge, so starting searching from all nodes isn’t efficient. Dgraph needs a place to start searching, that’s the root node.

At root, we use `func:`

and a function to find an initial set of nodes. So far we’ve used `eq`

and `allofterms`

for string search, but we can also search on other values like dates, numbers, and also filters on `count`

.

Dgraph needs to build an index on values that are to be searched in this way because, without an index to make the search efficient, Dgraph would have to trawl through the whole database to find matching values.

From the set of nodes matched in the root filter, Dgraph then follows edges to satisfy the remainder of the query. The filters on blocks inside the root are only applied to the nodes reached by following listed edges to them.

The root `func:`

only accepts a single function and doesn’t accept `AND`

, `OR`

and `NOT`

connectives as in filters. So the syntax `(func: ...) @filter(... AND ...)`

is required when filtering on multiple properties at the root.

Something to try: Find all people who are in their 20s, and have at least 2 friends.