redis/go-redis · error
invalid field value format
Error message
invalid field value format
What it means
Inside the FT.SEARCH fields array, every odd-position element (the field value) must be a string. RediSearch returns field values as bulk strings; any other Go type at that position (int64, nil, nested array) makes the parser abort with this error.
Source
Thrown at search_commands.go:2678
fields, ok := data[i].([]interface{})
if !ok {
if data[i] == proto.Nil || data[i] == nil {
doc.Error = proto.Nil
doc.Fields = map[string]string{}
fields = []interface{}{}
} else {
return FTSearchResult{}, fmt.Errorf("invalid document fields format")
}
}
for j := 0; j < len(fields); j += 2 {
key, ok := fields[j].(string)
if !ok {
return FTSearchResult{}, fmt.Errorf("invalid field key format")
}
value, ok := fields[j+1].(string)
if !ok {
return FTSearchResult{}, fmt.Errorf("invalid field value format")
}
doc.Fields[key] = value
}
i++
}
results = append(results, doc)
}
return FTSearchResult{
Total: int(total),
Docs: results,
}, nil
}
type FTSearchCmd struct {
baseCmd
val FTSearchResult
options *FTSearchOptionsView on GitHub (pinned to c5cad058c7)
Solutions
- Inspect the raw reply to find the non-string value
- Fix the mock/proxy so all field values are bulk strings
- Confirm you're on genuine Redis Stack / RediSearch (not a fork altering encodings)
- Upgrade go-redis in case a newer parser handles your server's encoding
Example fix
// before: mock uses an int field value
mock := []interface{}{int64(1), "doc:1", []interface{}{"count", 42}}
// after: values must be strings (as RediSearch sends them)
mock := []interface{}{int64(1), "doc:1", []interface{}{"count", "42"}} Defensive patterns
Strategy: validation
Validate before calling
// All field values in mocks must be strings, mirroring bulk-string encoding
for j := 1; j < len(fields); j += 2 {
if _, ok := fields[j].(string); !ok {
panic("field values must be strings")
}
} Type guard
func isStringValue(v interface{}) bool {
_, ok := v.(string)
return ok
} Try / catch
res, err := rdb.FTSearch(ctx, "idx", q).Result()
if err != nil {
if strings.Contains(err.Error(), "invalid field value") {
log.Printf("non-string field value in reply: %v", err)
return fallbackDocs, nil
}
return err
} Prevention
- Encode numeric field values as strings in mocks (RediSearch sends bulk strings)
- Verify no fork/proxy is returning integer-encoded field values
- Upgrade go-redis if a newer parser supports your server's encoding
When it happens
Trigger: FTSearch reply where a field value decodes to a non-string — e.g. numeric fields returned as RESP integers by a patched/proxied server, nil values, or mocks using non-string values.
Common situations: Proxies or middleware altering value encoding; hand-written mocks storing ints/floats for field values; module versions or third-party Redis forks changing field encoding.
Related errors
- unexpected search result format
- invalid total results format
- invalid document ID format
- invalid score format
- invalid document fields format
AI-assisted analysis of redis/go-redis@c5cad058c7 (2026-09-01).
Data as JSON: /api/errors/e34391a5b5908e75.
Report an issue: GitHub.