{"record":{"id":"cf4ff0e32f86eca8","repo":"dgraph-io/dgraph","slug":"predicate-s-is-not-indexed","errorCode":null,"errorMessage":"Predicate %s is not indexed","messagePattern":"Predicate (.+?) is not indexed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/task.go","lineNumber":1090,"sourceCode":"\nfunc (qs *queryState) helpProcessTask(ctx context.Context, q *pb.Query, gid uint32) (\n\t*pb.Result, error) {\n\n\tspan := trace.SpanFromContext(ctx)\n\tout := new(pb.Result)\n\tattr := q.Attr\n\n\tsrcFn, err := parseSrcFn(ctx, q)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif q.Reverse && !schema.State().IsReversed(ctx, attr) {\n\t\treturn nil, errors.Errorf(\"Predicate %s doesn't have reverse edge\", x.ParseAttr(attr))\n\t}\n\n\tif needsIndex(srcFn.fnType, q.UidList) && !schema.State().IsIndexed(ctx, q.Attr) {\n\t\treturn nil, errors.Errorf(\"Predicate %s is not indexed\", x.ParseAttr(q.Attr))\n\t}\n\n\tif len(q.Langs) > 0 && !schema.State().HasLang(attr) {\n\t\treturn nil, errors.Errorf(\"Language tags can only be used with predicates of string type\"+\n\t\t\t\" having @lang directive in schema. Got: [%v]\", x.ParseAttr(attr))\n\t}\n\tif len(q.Langs) == 1 && q.Langs[0] == \"*\" {\n\t\t// Reset the Langs fields. The ExpandAll field is set to true already so there's no\n\t\t// more need to store the star value in this field.\n\t\tq.Langs = nil\n\t}\n\n\ttyp, err := schema.State().TypeOf(attr)\n\tif err != nil {\n\t\t// All schema checks are done before this, this type is only used to\n\t\t// convert it to schema type before returning.\n\t\t// Schema type won't be present only if there is no data for that predicate\n\t\t// or if we load through bulk loader.","sourceCodeStart":1072,"sourceCodeEnd":1108,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/task.go#L1072-L1108","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Add an index: run `name: string @index(exact) .` in an alter/mutation schema update","Choose an index type matching the query (exact, hash, term, fulltext, trigram)","Rewrite the query to use a function supported without an index, or use @filter with has/uid","Verify current schema with `schema(pred: [name]) {}` before running the query"],"exampleFix":"// before (schema missing index)\nname: string .\n// after\nname: string @index(exact) .","handlingStrategy":"validation","validationCode":"// check schema before querying\nschema, _ := client.Query(context.Background(), `schema(pred: [name]) {}`)\n// ensure name has @index before running eq/allofterms etc.\nif !strings.Contains(schema.String(), \"@index\") {\n    client.Alter(ctx, &api.Operation{Schema: \"name: string @index(exact) .\"})\n}","typeGuard":null,"tryCatchPattern":"resp, err := client.Query(ctx, q)\nif err != nil && strings.Contains(err.Error(), \"is not indexed\") {\n    // alter schema to add the index, then retry the query\n    client.Alter(ctx, &api.Operation{Schema: \"name: string @index(exact) .\"})\n    resp, err = client.Query(ctx, q)\n}","preventionTips":["Define @index for every predicate used in value-filter functions at schema design time","Run `schema {}` in your test suite to assert required indexes exist","Re-check schema after any alter that drops or changes indexes"],"tags":["query","schema","index","dql"],"backgroundTag":"predicate-not-indexed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}