{"record":{"id":"79dfbf73e8601095","repo":"dgraph-io/dgraph","slug":"attribute-s-is-not-indexed","errorCode":null,"errorMessage":"Attribute %s is not indexed.","messagePattern":"Attribute (.+?) is not indexed\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"posting/index.go","lineNumber":62,"sourceCode":"\tfactorySpecs []*tok.FactoryCreateSpec\n\tedge         *pb.DirectedEdge // Represents the original uid -> value edge.\n\tval          types.Val\n\top           pb.DirectedEdge_Op\n}\n\n// indexTokens return tokens, without the predicate prefix and\n// index rune, for specific tokenizers.\nfunc indexTokens(ctx context.Context, info *indexMutationInfo) ([]string, error) {\n\tattr := info.edge.Attr\n\tlang := info.edge.GetLang()\n\n\tschemaType, err := schema.State().TypeOf(attr)\n\tif err != nil || !schemaType.IsScalar() {\n\t\treturn nil, errors.Errorf(\"Cannot index attribute %s of type object.\", attr)\n\t}\n\n\tif !schema.State().IsIndexed(ctx, attr) {\n\t\treturn nil, errors.Errorf(\"Attribute %s is not indexed.\", attr)\n\t}\n\tsv, err := types.Convert(info.val, schemaType)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar tokens []string\n\tfor _, it := range info.tokenizers {\n\t\ttoks, err := tok.BuildTokens(sv.Value, tok.GetTokenizerForLang(it, lang))\n\t\tif err != nil {\n\t\t\treturn tokens, err\n\t\t}\n\t\ttokens = append(tokens, toks...)\n\t}\n\treturn tokens, nil\n}\n\n// addIndexMutations adds mutation(s) for a single term, to maintain the index,","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/posting/index.go#L44-L80","documentation":"After confirming the attribute is scalar, indexTokens checks schema.State().IsIndexed; if the predicate has no @index directive in the schema, indexing is refused with 'Attribute %s is not indexed.' This ensures tokens are only built for predicates the schema declares indexable, keeping the index consistent with schema configuration.","triggerScenarios":"A mutation (AddMutationWithIndex → addIndexMutations → indexTokens) targets a scalar predicate that exists in the schema but lacks an index (no @index term), e.g. writing to 'name: string .' which has no hash/exact/term index.","commonSituations":"Inserting data before applying the @index schema update; schema altered to drop an index while old writers still push mutations; environment drift where the test cluster has indexes but production does not.","solutions":["Update the schema to add @index to the predicate (e.g. 'name: string @index(hash) .' via /alter) before writing data","Verify schema with 'schema(pred: name){}' or curl the /state endpoint that the index is present in the target cluster","Align deployment pipelines so schema alterations run before data loads","If the predicate genuinely should not be indexed, route the mutation through the non-indexing path"],"exampleFix":"// before: schema has 'name: string .'\n// after: alter schema first\ncurl -X POST localhost:8080/alter -d 'name: string @index(hash) .'\n// then retry the mutation","handlingStrategy":"validation","validationCode":"// Verify @index is present before writing\nsch, err := client.Schema(ctx, \"name\")\nif err != nil || len(sch.Index) == 0 {\n    return fmt.Errorf(\"predicate %q has no @index in schema; run alter first\", \"name\")\n}","typeGuard":"func isIndexed(sch *api.Schema) bool { return sch != nil && len(sch.Index) > 0 }","tryCatchPattern":"err := mutateWithIndex(ctx, edge)\nif err != nil && strings.Contains(err.Error(), \"is not indexed\") {\n    return fmt.Errorf(\"add @index to predicate %q via /alter before writing\", edge.Attr)\n}","preventionTips":["Run schema alterations in CI/CD before data migrations","Compare schema across environments (dev/staging/prod) to catch drift","Query the schema after each alter to confirm indexes took effect"],"tags":["indexing","schema","index-directive","mutation"],"backgroundTag":"predicate-not-indexed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}