{"id":"55ca365179bd073c","repo":"go-redis/redis","slug":"ft-create-schema-is-required","errorCode":null,"errorMessage":"FT.CREATE: SCHEMA is required","messagePattern":"FT\\.CREATE: SCHEMA is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":1448,"sourceCode":"\t\t\targs = append(args, \"NOHL\")\n\t\t}\n\t\tif options.NoFields {\n\t\t\targs = append(args, \"NOFIELDS\")\n\t\t}\n\t\tif options.NoFreqs {\n\t\t\targs = append(args, \"NOFREQS\")\n\t\t}\n\t\tif options.StopWords != nil {\n\t\t\targs = append(args, \"STOPWORDS\", len(options.StopWords))\n\t\t\targs = append(args, options.StopWords...)\n\t\t}\n\t\tif options.SkipInitialScan {\n\t\t\targs = append(args, \"SKIPINITIALSCAN\")\n\t\t}\n\t}\n\tif schema == nil {\n\t\tcmd := NewStatusCmd(ctx, args...)\n\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA is required\"))\n\t\treturn cmd\n\t}\n\targs = append(args, \"SCHEMA\")\n\tfor _, schema := range schema {\n\t\tif schema.FieldName == \"\" || schema.FieldType == SearchFieldTypeInvalid {\n\t\t\tcmd := NewStatusCmd(ctx, args...)\n\t\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA FieldName and FieldType are required\"))\n\t\t\treturn cmd\n\t\t}\n\t\targs = append(args, schema.FieldName)\n\t\tif schema.As != \"\" {\n\t\t\targs = append(args, \"AS\", schema.As)\n\t\t}\n\t\targs = append(args, schema.FieldType.String())\n\t\tif schema.VectorArgs != nil {\n\t\t\tif schema.FieldType != SearchFieldTypeVector {\n\t\t\t\tcmd := NewStatusCmd(ctx, args...)\n\t\t\t\tcmd.SetErr(fmt.Errorf(\"FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs\"))","sourceCodeStart":1430,"sourceCodeEnd":1466,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L1430-L1466","documentation":"Returned by FTCreate when the variadic schema argument is nil/empty. The FT.CREATE command requires at least one SCHEMA field definition; without fields RediSearch cannot build an index. go-redis performs this check client-side before sending anything to Redis and attaches the error to the returned *StatusCmd via SetErr.","triggerScenarios":"Calling FTCreate(ctx, index, opts) with no trailing *FieldSchema arguments, or passing an empty slice spread that resolves to nil. The check is `if schema == nil` at search_commands.go:1446.","commonSituations":"Building an index from a dynamically-assembled field list that happens to be empty (e.g. no columns match a filter), refactoring that drops the schema argument, or copy-paste from a minimal example that omitted the fields.","solutions":["Pass at least one non-nil *FieldSchema (e.g. &FieldSchema{FieldName: \"title\", FieldType: SearchFieldTypeText}) as a trailing argument to FTCreate.","If the field list is computed, guard for len(fields)==0 before calling and skip or log instead of calling FTCreate with an empty schema.","Inspect cmd.Err() immediately after FTCreate so the failure surfaces during development rather than being silently ignored."],"exampleFix":"// before\nclient.FTCreate(ctx, \"myidx\", &redis.FTCreateOptions{})\n\n// after\nclient.FTCreate(ctx, \"myidx\", &redis.FTCreateOptions{},\n    &redis.FieldSchema{FieldName: \"title\", FieldType: redis.SearchFieldTypeText},\n)","handlingStrategy":"validation","validationCode":"if len(fields) == 0 {\n    return fmt.Errorf(\"cannot create index %q: at least one schema field is required\", index)\n}\ncmd := client.FTCreate(ctx, index, opts, fields...)","typeGuard":null,"tryCatchPattern":"if err := cmd.Err(); err != nil {\n    if strings.Contains(err.Error(), \"SCHEMA is required\") {\n        // build/seed the schema and retry\n    }\n}","preventionTips":["Never call FTCreate with an empty schema slice; guard len before the call.","Always check the *StatusCmd returned by FTCreate with .Err().","Centralize index creation in one function so the schema is always validated."],"tags":["redisearch","ft-create","schema","validation","client-side"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}