{"record":{"id":"d4fa921fc365c0c8","repo":"dgraph-io/dgraph","slug":"attribute-s-is-not-indexed-d4fa92","errorCode":null,"errorMessage":"Attribute %s is not indexed.","messagePattern":"Attribute (.+?) is not indexed\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/tokens.go","lineNumber":81,"sourceCode":"\t\tlang = \"en\"\n\t}\n\tif funcType == fullTextSearchFn {\n\t\treturn tok.GetFullTextTokens(funcArgs, lang)\n\t}\n\tif funcType == ngramFn {\n\t\tif query {\n\t\t\treturn tok.GetNGramQueryTokens(funcArgs, lang)\n\t\t} else {\n\t\t\treturn tok.GetNGramTokens(funcArgs, lang)\n\t\t}\n\t}\n\treturn tok.GetTermTokens(funcArgs)\n}\n\nfunc pickTokenizer(ctx context.Context, attr string, f string) (tok.Tokenizer, error) {\n\t// Get the tokenizers and choose the corresponding one.\n\tif !schema.State().IsIndexed(ctx, attr) {\n\t\treturn nil, errors.Errorf(\"Attribute %s is not indexed.\", attr)\n\t}\n\n\ttokenizers := schema.State().Tokenizer(ctx, attr)\n\tif tokenizers == nil {\n\t\treturn nil, errors.Errorf(\"Schema state not found for %s.\", attr)\n\t}\n\tfor _, t := range tokenizers {\n\t\t// If function is eq and we found a tokenizer that's !Lossy(), lets return it\n\t\tswitch f {\n\t\tcase \"eq\":\n\t\t\t// For equality, find a non-lossy tokenizer.\n\t\t\tif !t.IsLossy() {\n\t\t\t\treturn t, nil\n\t\t\t}\n\t\tdefault:\n\t\t\t// rest of the cases: ge, gt, le, lt require a sortable tokenizer.\n\t\t\tif t.IsSortable() {\n\t\t\t\treturn t, nil","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/tokens.go#L63-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Verify the predicate name in the query matches the indexed attribute (check for typos).","Confirm the index build finished after altering the schema before running comparison queries."],"exampleFix":"// before (schema)\nname: string .\n// after\nname: string @index(hash) .","handlingStrategy":"validation","validationCode":"schema, _ := dg.NewOperation(client).WithSchema(\"schema: name: string @index(hash) .\").Do(ctx)\n// or check client-side via the /state or schema endpoint that the predicate has an index before querying\nresp, _ := dg.Query(ctx, `schema(pred: \"name\") {}`)\n// verify resp shows @index for the predicate","typeGuard":null,"tryCatchPattern":"if err := runQuery(ctx); err != nil && strings.Contains(err.Error(), \"is not indexed\") {\n    return fmt.Errorf(\"add an @index to predicate in schema, then retry: %w\", err)\n}","preventionTips":["Fetch the current schema at startup and assert required predicates have indexes.","Always add indexes for predicates used in eq/comparison functions.","Watch for predicate-name typos between queries and schema."],"tags":["dgraph","schema","indexing","dql"],"backgroundTag":"attribute-not-indexed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}