dgraph-io/dgraph · error

Attribute %s is not indexed.

Error message

Attribute %s is not indexed.

What it means

pickTokenizer validates that the attribute used in a comparison/equality function (e.g. eq, le, ge with string predicates) is indexed before looking up its tokenizers. schema.State().IsIndexed returns false for predicates without an index, so this error is thrown instead of attempting to tokenize an unindexed predicate.

Source

Thrown at worker/tokens.go:81

		lang = "en"
	}
	if funcType == fullTextSearchFn {
		return tok.GetFullTextTokens(funcArgs, lang)
	}
	if funcType == ngramFn {
		if query {
			return tok.GetNGramQueryTokens(funcArgs, lang)
		} else {
			return tok.GetNGramTokens(funcArgs, lang)
		}
	}
	return tok.GetTermTokens(funcArgs)
}

func pickTokenizer(ctx context.Context, attr string, f string) (tok.Tokenizer, error) {
	// Get the tokenizers and choose the corresponding one.
	if !schema.State().IsIndexed(ctx, attr) {
		return nil, errors.Errorf("Attribute %s is not indexed.", attr)
	}

	tokenizers := schema.State().Tokenizer(ctx, attr)
	if tokenizers == nil {
		return nil, errors.Errorf("Schema state not found for %s.", attr)
	}
	for _, t := range tokenizers {
		// If function is eq and we found a tokenizer that's !Lossy(), lets return it
		switch f {
		case "eq":
			// For equality, find a non-lossy tokenizer.
			if !t.IsLossy() {
				return t, nil
			}
		default:
			// rest of the cases: ge, gt, le, lt require a sortable tokenizer.
			if t.IsSortable() {
				return t, nil

View on GitHub (pinned to 759e242be6)

Solutions

  1. Add the appropriate index to the predicate in the schema (hash/exact/term/trigram for strings; int/float/datetime indexes for inequalities) and wait for indexing to complete.
  2. Verify the predicate name in the query matches the indexed attribute (check for typos).
  3. Confirm the index build finished after altering the schema before running comparison queries.

Example fix

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

Strategy: validation

Validate before calling

schema, _ := dg.NewOperation(client).WithSchema("schema: name: string @index(hash) .").Do(ctx)
// or check client-side via the /state or schema endpoint that the predicate has an index before querying
resp, _ := dg.Query(ctx, `schema(pred: "name") {}`)
// verify resp shows @index for the predicate

Try / catch

if err := runQuery(ctx); err != nil && strings.Contains(err.Error(), "is not indexed") {
    return fmt.Errorf("add an @index to predicate in schema, then retry: %w", err)
}

Prevention

When it happens

Trigger: Running a DQL query that uses a comparison function on a predicate with no index in the schema, e.g. 'eq(name, "alice")' where name has no hash/exact/trigram index, or 'ge(score, ...)' on an unindexed predicate. Raised from handleCompareFunction and getInequalityTokens.

Common situations: Fresh schema where indexes were never added; querying a predicate added after initial deployment without running index creation and a rebuild; typos in predicate names so an unindexed predicate is referenced instead of the indexed one.

Related errors


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