go-redis/redis · error

invalid field key format

Error message

invalid field key format

What it means

Returned by ProcessAggregateResult when iterating a RESP2 row's flat [key, value, ...] array and a key-position element is not a string. Field names in FT.AGGREGATE rows must be bulk strings; a non-string key (number, nil, nested type) indicates a malformed or shifted row.

Source

Thrown at search_commands.go:936

	}

	total, ok := data[0].(int64)
	if !ok {
		return nil, fmt.Errorf("invalid total format")
	}

	rows := make([]AggregateRow, 0, len(data)-1)
	for _, row := range data[1:] {
		fields, ok := row.([]interface{})
		if !ok {
			return nil, fmt.Errorf("invalid row format")
		}

		rowMap := make(map[string]interface{})
		for i := 0; i < len(fields); i += 2 {
			key, ok := fields[i].(string)
			if !ok {
				return nil, fmt.Errorf("invalid field key format")
			}
			value := fields[i+1]
			rowMap[key] = value
		}
		rows = append(rows, AggregateRow{Fields: rowMap})
	}

	result := &FTAggregateResult{
		Total: int(total),
		Rows:  rows,
	}
	return result, nil
}

func NewAggregateCmd(ctx context.Context, args ...interface{}) *AggregateCmd {
	return &AggregateCmd{
		baseCmd: baseCmd{
			ctx:     ctx,

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Inspect cmd.RawVal() to see the exact row contents and locate the non-string key.
  2. Confirm the row array has an even length (an odd length implies truncation upstream).
  3. Verify protocol negotiation and server version against the expected FT.AGGREGATE reply shape.
  4. Reproduce with redis-cli; if the server emits the non-string key, report it upstream.
Defensive patterns

Strategy: try-catch

Try / catch

res, err := cmd.Result()
if err != nil && strings.Contains(err.Error(), "invalid field key format") {
    raw, _ := cmd.RawResult()
    log.Printf("aggregate field key not string; raw=%v", raw)
}
return err

Prevention

When it happens

Trigger: AggregateCmd.readReply decoding a RESP2 row where fields[i] (i even) is not a string. Triggered during row decoding inside ProcessAggregateResult.

Common situations: An odd-length row shifted key/value alignment (the loop assumes even=keys). Server/proxy bug emitting a non-string key. RESP3/RESP2 mismatch. A NULL placeholder where a field key was expected.

Related errors


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