redis/redis-rb · error · Redis::CommandError
Invalid value for numeric field '#{field_name}': #{value}
Error message
Invalid value for numeric field '#{field_name}': #{value} What it means
Error "Invalid value for numeric field '#{field_name}': #{value}" thrown in redis/redis-rb.
Source
Thrown at lib/redis/commands/modules/search/index.rb:112
# +{"brand":"x"}+ which +$.brand+ matches). It does *not* build nested structure: a field
# over a nested path (+$.user.name AS name+) is not satisfied by a flat +name: "..."+
# write — pass the full document shape instead (+add("1", user: { name: "Ann" })+).
#
# @example
# index.add("1", title: "hello", price: 10)
#
# @param doc_id [String] the logical document id
# @param fields [Hash{Symbol,String => Object}] the field/value pairs to store
# @return [Integer, String] the +HSET+ reply (HASH index) or the +JSON.SET+ reply (JSON index)
# @raise [Redis::CommandError] if a value for a {NumericField} is not Numeric, or the write fails
def add(doc_id, **fields)
key = @prefix ? "#{@prefix}#{doc_id}" : doc_id
# Validate fields
fields.each do |field_name, value|
field = @schema.field(field_name)
if field.is_a?(NumericField) && !value.is_a?(Numeric)
raise Redis::CommandError, "Invalid value for numeric field '#{field_name}': #{value}"
end
end
begin
json? ? @redis.json_set(key, "$", fields) : @redis.hset(key, fields)
rescue Redis::CommandError => error
raise Redis::CommandError, "Error adding document: #{error.message}"
end
end
# Search the index.
#
# Accepts a {Query} object, a raw query string, or a block evaluated as a {Query}. Keyword
# arguments are applied on top of the query before it is sent. Document ids in the result
# have the index prefix stripped, so they match the ids passed to {#add}.
#
# @example with a Query object
# index.search(Redis::Commands::Search::Query.new("@title:hello").paging(0, 10))View on GitHub (pinned to 2ba9010b91)
Solutions
- Pass a numeric value (Integer or Float) for the numeric field, e.g. add_document(field_name: 42).
- Coerce the value with to_i or to_f before adding the document if it arrives as a string.
When it happens
Trigger: Thrown at lib/redis/commands/modules/search/index.rb:112 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of redis/redis-rb@2ba9010b91 (2026-08-23).
Data as JSON: /api/errors/32c67f500bc3f977.
Report an issue: GitHub.