go-redis/redis · error

unexpected search result format

Error message

unexpected search result format

What it means

Returned by parseFTSearch when the reply array has fewer than 1 element. The FT.SEARCH reply always begins with a total-count integer; an empty reply means the server returned an unexpected (empty) payload. Guard at search_commands.go:2607.

Source

Thrown at search_commands.go:2608

		val = make([]SpellCheckResult, len(cmd.val))
		for i, result := range cmd.val {
			val[i] = SpellCheckResult{
				Term: result.Term,
			}
			if result.Suggestions != nil {
				val[i].Suggestions = slices.Clone(result.Suggestions)
			}
		}
	}
	return &FTSpellCheckCmd{
		baseCmd: cmd.cloneBaseCmd(),
		val:     val,
	}
}

func parseFTSearch(data []interface{}, noContent, withScores, withPayloads, withSortKeys bool) (FTSearchResult, error) {
	if len(data) < 1 {
		return FTSearchResult{}, fmt.Errorf("unexpected search result format")
	}

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

	var results []Document
	for i := 1; i < len(data); {
		docID, ok := data[i].(string)
		if !ok {
			return FTSearchResult{}, fmt.Errorf("invalid document ID format")
		}

		doc := Document{
			ID:     docID,
			Fields: make(map[string]string),
		}

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Confirm the server is reachable and the index exists before searching.
  2. Check for a RESP-rewriting proxy and ensure the client Protocol setting matches the server.
  3. Inspect the raw connection/reply (enable go-redis logging) to see if the frame was truncated.

Example fix

null
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure index exists and server reachable before searching:
if _, err := client.FTInfo(ctx, idx).Result(); err != nil {
    return fmt.Errorf("index %q unavailable: %w", idx, err)
}

Try / catch

res, err := client.FTSearch(ctx, idx, q).Result()
if err != nil && strings.Contains(err.Error(), "unexpected search result format") {
    // re-issue FTInfo to confirm index/server health; enable go-redis logging
}

Prevention

When it happens

Trigger: Calling FTSearch and the parsed reply data slice is empty (len(data) < 1). Typically a protocol/truncation issue rather than a normal zero-results case (zero results still returns a 1-element array with total 0).

Common situations: A proxy truncating replies, a RESP3/RESP2 mismatch causing the reader to consume the frame incorrectly, or a server crash mid-reply. Distinct from a legitimate empty search which returns [0].

Related errors


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