go-redis/redis · error
FT.CREATE: SCHEMA FieldName and FieldType are required
Error message
FT.CREATE: SCHEMA FieldName and FieldType are required
What it means
Returned by FTCreate when a FieldSchema entry has an empty FieldName or FieldType==SearchFieldTypeInvalid. Both are mandatory because RediSearch needs a name and a concrete type token (TEXT/NUMERIC/TAG/...). SearchFieldTypeInvalid is the zero value (String() returns ""), so an uninitialized FieldSchema trips this guard at search_commands.go:1453.
Source
Thrown at search_commands.go:1455
}
if options.StopWords != nil {
args = append(args, "STOPWORDS", len(options.StopWords))
args = append(args, options.StopWords...)
}
if options.SkipInitialScan {
args = append(args, "SKIPINITIALSCAN")
}
}
if schema == nil {
cmd := NewStatusCmd(ctx, args...)
cmd.SetErr(fmt.Errorf("FT.CREATE: SCHEMA is required"))
return cmd
}
args = append(args, "SCHEMA")
for _, schema := range schema {
if schema.FieldName == "" || schema.FieldType == SearchFieldTypeInvalid {
cmd := NewStatusCmd(ctx, args...)
cmd.SetErr(fmt.Errorf("FT.CREATE: SCHEMA FieldName and FieldType are required"))
return cmd
}
args = append(args, schema.FieldName)
if schema.As != "" {
args = append(args, "AS", schema.As)
}
args = append(args, schema.FieldType.String())
if schema.VectorArgs != nil {
if schema.FieldType != SearchFieldTypeVector {
cmd := NewStatusCmd(ctx, args...)
cmd.SetErr(fmt.Errorf("FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs"))
return cmd
}
// Check mutual exclusivity of vector options
optionCount := 0
if schema.VectorArgs.FlatOptions != nil {
optionCount++
}View on GitHub (pinned to 36d97525cd)
Solutions
- Set both FieldName (non-empty string) and FieldType (e.g. SearchFieldTypeText, SearchFieldTypeTag) on every FieldSchema.
- Validate each FieldSchema in a helper before calling FTCreate to fail early with a clearer message.
- Linter/assertion: ensure no FieldSchema in the slice has FieldType == SearchFieldTypeInvalid.
Example fix
// before
&redis.FieldSchema{FieldName: "", FieldType: redis.SearchFieldTypeInvalid}
// after
&redis.FieldSchema{FieldName: "title", FieldType: redis.SearchFieldTypeText} Defensive patterns
Strategy: validation
Validate before calling
for i, f := range fields {
if f.FieldName == "" || f.FieldType == redis.SearchFieldTypeInvalid {
return fmt.Errorf("fields[%d]: FieldName and FieldType are required", i)
}
} Type guard
func isValidFieldSchema(f *redis.FieldSchema) bool {
return f != nil && f.FieldName != "" && f.FieldType != redis.SearchFieldTypeInvalid
} Try / catch
if err := cmd.Err(); err != nil {
if strings.Contains(err.Error(), "FieldName and FieldType are required") {
// inspect each FieldSchema for blanks
}
} Prevention
- Treat the zero-value FieldSchema as a bug; never pass &redis.FieldSchema{}.
- Validate the schema slice in a loop before FTCreate.
- Add a test asserting every FieldSchema has a non-empty name and non-Invalid type.
When it happens
Trigger: Passing a &FieldSchema{} literal with FieldName unset, setting FieldType via a variable that defaulted to zero, or constructing schemas in a loop where one iteration leaves the fields blank.
Common situations: Forgetting to set FieldType when the zero value is acceptable-looking (it compiles to the Invalid iota), populating FieldName from a config key that is missing, or partial struct copy that dropped FieldType.
Related errors
- FT.CREATE: SCHEMA is required
- FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArg
- FT.CREATE: SCHEMA VectorArgs must have exactly one of FlatOp
- FT.CREATE: SCHEMA FieldType GEOSHAPE is required for GeoShap
- FT.CREATE: Type, Dim and DistanceMetric are required for VEC
AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06).
Data as JSON: /data/errors/5489ba6e8c7ec09f.json.
Report an issue: GitHub.