dgraph-io/dgraph · error

Predicate %s is not indexed

Error message

Predicate %s is not indexed

What it means

When processing a query task whose source function needs an index (e.g. eq, allofterms on a value), helpProcessTask verifies the predicate is indexed in the schema. If not, it rejects the query because these functions require an index to be evaluated efficiently.

Source

Thrown at worker/task.go:1090

func (qs *queryState) helpProcessTask(ctx context.Context, q *pb.Query, gid uint32) (
	*pb.Result, error) {

	span := trace.SpanFromContext(ctx)
	out := new(pb.Result)
	attr := q.Attr

	srcFn, err := parseSrcFn(ctx, q)
	if err != nil {
		return nil, err
	}

	if q.Reverse && !schema.State().IsReversed(ctx, attr) {
		return nil, errors.Errorf("Predicate %s doesn't have reverse edge", x.ParseAttr(attr))
	}

	if needsIndex(srcFn.fnType, q.UidList) && !schema.State().IsIndexed(ctx, q.Attr) {
		return nil, errors.Errorf("Predicate %s is not indexed", x.ParseAttr(q.Attr))
	}

	if len(q.Langs) > 0 && !schema.State().HasLang(attr) {
		return nil, errors.Errorf("Language tags can only be used with predicates of string type"+
			" having @lang directive in schema. Got: [%v]", x.ParseAttr(attr))
	}
	if len(q.Langs) == 1 && q.Langs[0] == "*" {
		// Reset the Langs fields. The ExpandAll field is set to true already so there's no
		// more need to store the star value in this field.
		q.Langs = nil
	}

	typ, err := schema.State().TypeOf(attr)
	if err != nil {
		// All schema checks are done before this, this type is only used to
		// convert it to schema type before returning.
		// Schema type won't be present only if there is no data for that predicate
		// or if we load through bulk loader.

View on GitHub (pinned to 759e242be6)

Solutions

  1. Add an index: run `name: string @index(exact) .` in an alter/mutation schema update
  2. Choose an index type matching the query (exact, hash, term, fulltext, trigram)
  3. Rewrite the query to use a function supported without an index, or use @filter with has/uid
  4. Verify current schema with `schema(pred: [name]) {}` before running the query

Example fix

// before (schema missing index)
name: string .
// after
name: string @index(exact) .
Defensive patterns

Strategy: validation

Validate before calling

// check schema before querying
schema, _ := client.Query(context.Background(), `schema(pred: [name]) {}`)
// ensure name has @index before running eq/allofterms etc.
if !strings.Contains(schema.String(), "@index") {
    client.Alter(ctx, &api.Operation{Schema: "name: string @index(exact) ."})
}

Try / catch

resp, err := client.Query(ctx, q)
if err != nil && strings.Contains(err.Error(), "is not indexed") {
    // alter schema to add the index, then retry the query
    client.Alter(ctx, &api.Operation{Schema: "name: string @index(exact) ."})
    resp, err = client.Query(ctx, q)
}

Prevention

When it happens

Trigger: Running a query with functions like eq, lt, allofterms, anyofterms, alloftext, etc., on a predicate whose schema lacks an index (no @index directive or the index was dropped).

Common situations: Querying a value predicate without @index in schema; schema altered to remove an index while old queries still run; uid predicates used with value functions by mistake.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/cf4ff0e32f86eca8. Report an issue: GitHub.