Dgraph GraphQL Tour

Search

Indexes

When Dgraph searches for strings, dates, or other values based on a filter, it needs an index to make the search efficient. We’ve already seen examples of how to specify the indexes in a schema update.

Int, Float, and DateTime have default indexes, but String has a few options for which search index types to use. You can build multiple indexes for the same String-valued predicate.

For String, the following indexes are available:

  • term: Used when filtering by “all terms” or by “any terms”; generates filter inputs allofterms and anyofterms
  • exact: for use with inequality, matches a whole string and generates the following filter inputs: lt (<), le (<=), eq (=), ge (>=), gt (>), and in (not equal)
  • hash: Used similarly to exact, but hashes the string to accommodate longer strings; generates the following filter inputs: eq (equal) and in (not equal)
  • fulltext: Used for full-text search-engine style search; generates the following filter inputs alloftext and anyoftext
  • regexp: Used with regular expression searches; generates the regexp filter input

You specify multiple indexes as a list passed to the by argument of the @search directive.

Apply the schema mutation to apply the new indexes and types on your database. It may take a minute for Dgraph to compute these new indexes if working with a larger data graph. Let the schema push operation run, and then move on after it’s finished.

5.1 Indexes