go-redis/redis · error

FT.CREATE: SCHEMA is required

Error message

FT.CREATE: SCHEMA is required

What it means

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.

Source

Thrown at search_commands.go:1448

			args = append(args, "NOHL")
		}
		if options.NoFields {
			args = append(args, "NOFIELDS")
		}
		if options.NoFreqs {
			args = append(args, "NOFREQS")
		}
		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"))

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Pass at least one non-nil *FieldSchema (e.g. &FieldSchema{FieldName: "title", FieldType: SearchFieldTypeText}) as a trailing argument to FTCreate.
  2. 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.
  3. Inspect cmd.Err() immediately after FTCreate so the failure surfaces during development rather than being silently ignored.

Example fix

// before
client.FTCreate(ctx, "myidx", &redis.FTCreateOptions{})

// after
client.FTCreate(ctx, "myidx", &redis.FTCreateOptions{},
    &redis.FieldSchema{FieldName: "title", FieldType: redis.SearchFieldTypeText},
)
Defensive patterns

Strategy: validation

Validate before calling

if len(fields) == 0 {
    return fmt.Errorf("cannot create index %q: at least one schema field is required", index)
}
cmd := client.FTCreate(ctx, index, opts, fields...)

Try / catch

if err := cmd.Err(); err != nil {
    if strings.Contains(err.Error(), "SCHEMA is required") {
        // build/seed the schema and retry
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/55ca365179bd073c.json. Report an issue: GitHub.