{"record":{"id":"f4adb94705512c3d","repo":"dgraph-io/dgraph","slug":"require-type-of-tokenizer-for-pred-s-of-type-s","errorCode":null,"errorMessage":"Require type of tokenizer for pred: %s of type: %s for indexing.","messagePattern":"Require type of tokenizer for pred: (.+?) of type: (.+?) for indexing\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/parse.go","lineNumber":430,"sourceCode":"\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\n\t\tvar seen = make(map[string]bool)\n\t\tvar seenSortableTok bool\n\t\tfor _, t := range schema.Tokenizer {\n\t\t\ttokenizer, has := tok.GetTokenizer(t)\n\t\t\tif !has {\n\t\t\t\treturn errors.Errorf(\"Invalid tokenizer %s\", t)\n\t\t\t}\n\t\t\ttokenizerType, ok := types.TypeForName(tokenizer.Type())\n\t\t\tx.AssertTrue(ok) // Type is validated during tokenizer loading.\n\t\t\tif tokenizerType != typ {","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/schema/parse.go#L412-L448","documentation":"If a predicate is marked @index (Directive == SchemaUpdate_INDEX) but no tokenizers (or vector index spec) are provided, resolveTokenizers cannot build the index and returns this error naming the predicate and its type. In Dgraph, indexed string/other predicates require at least one tokenizer (hash, exact, term, fulltext, etc.) so the index knows how to encode values.","triggerScenarios":"Altering schema with `pred: string @index .` (no tokenizer list) or an API SchemaUpdate with Directive=INDEX and empty Tokenizer array and no vector index spec.","commonSituations":"Hand-written DQL schema where the tokenizer list was forgotten; programmatic schema clients (go/pydgraph) building SchemaUpdate structs with Directive set but Tokenizer nil; migrations generated from other DBs that only say 'indexed: true'.","solutions":["Add a tokenizer: e.g. `pred: string @index(hash) .` or `@index(term, fulltext)` for strings, `@index(int)`/`@index(float)`/`@index(datetime)` for others.","For vector embeddings, supply the vector index specification (metric/dimension) instead of / in addition to tokenizers.","Drop the @index directive if you don't need to filter/sort on the predicate.","Re-apply the schema alteration."],"exampleFix":"// before\nname: string @index .\n// after\nname: string @index(hash) .","handlingStrategy":"validation","validationCode":"function requireTokenizer(schemaLine) {\n  const m = schemaLine.match(/@(index)\\s*(\\([^)]*\\))?\\s*\\./);\n  if (m && m[1] === 'index' && !m[2]) {\n    throw new Error('indexed predicate needs a tokenizer: @index(hash) etc.');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await dgraph.Alter(ctx, op);\n} catch (e) {\n  if (String(e).includes('Require type of tokenizer')) {\n    // re-send SchemaUpdate with Tokenizer populated\n  }\n  throw e;\n}","preventionTips":["Always list at least one tokenizer with @index in DQL","In go/pydgraph, set SchemaUpdate.Tokenizer whenever Directive == INDEX (or supply vector index spec)","Add schema linting to CI","Verify vector predicates carry metric/dimension specs"],"tags":["dgraph","schema","indexing","tokenizer"],"backgroundTag":"schema-validation-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}