{"id":"9c52566be1ee7437","repo":"go-redis/redis","slug":"invalid-document-fields-format","errorCode":null,"errorMessage":"invalid document fields format","messagePattern":"invalid document fields format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":2667,"sourceCode":"\t\t\t}\n\t\t}\n\n\t\tif withSortKeys && i < len(data) {\n\t\t\tif sortKey, ok := data[i].(string); ok {\n\t\t\t\tdoc.SortKey = &sortKey\n\t\t\t\ti++\n\t\t\t}\n\t\t}\n\n\t\tif i < len(data) {\n\t\t\tfields, ok := data[i].([]interface{})\n\t\t\tif !ok {\n\t\t\t\tif data[i] == proto.Nil || data[i] == nil {\n\t\t\t\t\tdoc.Error = proto.Nil\n\t\t\t\t\tdoc.Fields = map[string]string{}\n\t\t\t\t\tfields = []interface{}{}\n\t\t\t\t} else {\n\t\t\t\t\treturn FTSearchResult{}, fmt.Errorf(\"invalid document fields format\")\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor j := 0; j < len(fields); j += 2 {\n\t\t\t\tkey, ok := fields[j].(string)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn FTSearchResult{}, fmt.Errorf(\"invalid field key format\")\n\t\t\t\t}\n\t\t\t\tvalue, ok := fields[j+1].(string)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn FTSearchResult{}, fmt.Errorf(\"invalid field value format\")\n\t\t\t\t}\n\t\t\t\tdoc.Fields[key] = value\n\t\t\t}\n\t\t\ti++\n\t\t}\n\n\t\tresults = append(results, doc)","sourceCodeStart":2649,"sourceCodeEnd":2685,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L2649-L2685","documentation":"Returned in parseFTSearch (search_commands.go:2660-2668): after the doc ID (and optional score/payload/sortkey), the next element must be either an array of field pairs, nil/RESP nil, or it errors here. A scalar (string, int) where the fields array is expected trips this.","triggerScenarios":"Reply shape mismatch — e.g. NOCONTENT was not set on the client but the server omitted fields, or an alternate reply mode (LOAD/RETURN) collapsed fields into a scalar.","commonSituations":"Mismatched NoContent between request and server, RETURN reducing fields unexpectedly, or a malformed reply from a proxy.","solutions":["Check that NoContent is false only when you really expect field arrays.","Inspect RawResult() to see the element at the failing index.","Re-run via redis-cli to see canonical shape.","Upgrade Redis Stack and go-redis to remove any parser drift."],"exampleFix":"// before — server returned IDs only but NoContent was left false\nres, err := client.FTSearchWithArgs(ctx, idx, q, &redis.FTSearchOptions{}).Result()\n// after — set NoContent when fields are not expected\nres, err := client.FTSearchWithArgs(ctx, idx, q, &redis.FTSearchOptions{NoContent: true}).Result()","handlingStrategy":"validation","validationCode":"// Set NoContent when you do not need field arrays, so the parser skips the fields slot.\nif !needFields {\n    opts.NoContent = true\n}","typeGuard":null,"tryCatchPattern":"res, err := client.FTSearchWithArgs(ctx, idx, q, opts).Result()\nif err != nil && strings.Contains(err.Error(), \"invalid document fields format\") {\n    raw, _ := client.FTSearchWithArgs(ctx, idx, q, opts).RawResult()\n    log.Printf(\"fields slot not array; raw=%#v\", raw)\n}","preventionTips":["Set NoContent when fields are not required.","Inspect RawResult() for the failing element.","Keep RETURN/LOAD clauses consistent with the schema."],"tags":["redisearch","ft-search","resp2","response-parsing"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}