{"record":{"id":"6dfadcbfb58f3284","repo":"dgraph-io/dgraph","slug":"indexing-not-allowed-on-predicate-s-of-type-s","errorCode":null,"errorMessage":"Indexing not allowed on predicate %s of type %s","messagePattern":"Indexing not allowed on predicate (.+?) of type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/parse.go","lineNumber":420,"sourceCode":"\toptVal := nextItem.Val[1 : len(nextItem.Val)-1]\n\treturn &pb.OptionPair{Key: optName, Value: optVal}, nil\n}\n\nfunc HasTokenizerOrVectorIndexSpec(update *pb.SchemaUpdate) bool {\n\tif update == nil {\n\t\treturn false\n\t}\n\treturn len(update.Tokenizer) > 0 || len(update.IndexSpecs) > 0\n}\n\n// resolveTokenizers resolves default tokenizers and verifies tokenizers definitions.\nfunc resolveTokenizers(updates []*pb.SchemaUpdate) error {\n\tfor _, schema := range updates {\n\t\ttyp := types.TypeID(schema.ValueType)\n\n\t\tif (typ == types.UidID || typ == types.DefaultID || typ == types.PasswordID) &&\n\t\t\tschema.Directive == pb.SchemaUpdate_INDEX {\n\t\t\treturn errors.Errorf(\"Indexing not allowed on predicate %s of type %s\",\n\t\t\t\tx.ParseAttr(schema.Predicate), typ.Name())\n\t\t}\n\n\t\tif typ == types.UidID {\n\t\t\tcontinue\n\t\t}\n\n\t\tif !HasTokenizerOrVectorIndexSpec(schema) &&\n\t\t\tschema.Directive == pb.SchemaUpdate_INDEX {\n\t\t\treturn errors.Errorf(\n\t\t\t\t\"Require type of tokenizer for pred: %s of type: %s for indexing.\",\n\t\t\t\tschema.Predicate, typ.Name())\n\t\t} else if HasTokenizerOrVectorIndexSpec(schema) &&\n\t\t\tschema.Directive != pb.SchemaUpdate_INDEX {\n\t\t\treturn errors.Errorf(\"Tokenizers present without indexing on attr %s\",\n\t\t\t\tx.ParseAttr(schema.Predicate))\n\t\t}\n\t\t// check for valid tokenizer types and duplicates","sourceCodeStart":402,"sourceCodeEnd":438,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/schema/parse.go#L402-L438","documentation":"When applying a schema update, resolveTokenizers rejects an @index directive on predicates whose type cannot be indexed: uid, default (untyped), or password. These types have no tokenizers, so indexing them is meaningless and the schema is refused. The error names the predicate (via x.ParseAttr) and its type.","triggerScenarios":"A DQL schema alteration adding @index to a predicate declared as uid, default, or password, e.g. `name: password @index(term) .` or an @upsert/ACHEMA call marking a uid predicate with an index directive.","commonSituations":"Copy-pasted schema lines carrying @index onto password fields (common for intended-but-unsupported exact search on secrets); new predicates with no type yet (`pred: string` omitted so it defaults) that were given @index; migrations that blanket-apply @index to every predicate.","solutions":["Remove the @index directive from uid/default/password predicates.","Give the predicate a concrete indexable type (string, int, float, bool, datetime, etc.) if you truly need indexing.","If you need to look up users by password-like fields, store a separate hash/salted field of type string with an appropriate tokenizer.","Re-run the schema alteration after fixing the type/directive combination."],"exampleFix":"// before\nuser_password: password @index(exact) .\nfriend: [uid] @index(hash) .\n// after\nuser_password: password .\nfriend: [uid] .\nlookup_key: string @index(exact) .","handlingStrategy":"validation","validationCode":"const nonIndexable = new Set(['uid', 'default', 'password']);\nfunction validateSchemaLine(line) {\n  const m = line.match(/^(\\w+):\\s*([\\w\\[\\]]+)\\s*(\\.[^.]*)?@index/);\n  if (m && nonIndexable.has(m[2].replace(/\\[|\\]/g, ''))) {\n    throw new Error(`@index not allowed on ${m[1]} of type ${m[2]}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dgraph.Alter(ctx, op);\n} catch (e) {\n  if (String(e).includes('Indexing not allowed on predicate')) {\n    // strip @index from uid/default/password predicates and retry\n  }\n  throw e;\n}","preventionTips":["Never add @index to uid, password, or untyped (default) predicates","Lint schema files before Alter in CI","For secret lookups, use a separate string hash field","Review migrations that blanket-add @index to all predicates"],"tags":["dgraph","schema","indexing"],"backgroundTag":"schema-validation-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}