{"record":{"id":"32c67f500bc3f977","repo":"redis/redis-rb","slug":"invalid-value-for-numeric-field-field-name","errorCode":null,"errorMessage":"Invalid value for numeric field '#{field_name}': #{value}","messagePattern":"Invalid value for numeric field '#(.+?)': #(.+?)","errorType":"exception","errorClass":"Redis::CommandError","httpStatus":null,"severity":"error","filePath":"lib/redis/commands/modules/search/index.rb","lineNumber":112,"sourceCode":"        # +{\"brand\":\"x\"}+ which +$.brand+ matches). It does *not* build nested structure: a field\n        # over a nested path (+$.user.name AS name+) is not satisfied by a flat +name: \"...\"+\n        # write — pass the full document shape instead (+add(\"1\", user: { name: \"Ann\" })+).\n        #\n        # @example\n        #   index.add(\"1\", title: \"hello\", price: 10)\n        #\n        # @param doc_id [String] the logical document id\n        # @param fields [Hash{Symbol,String => Object}] the field/value pairs to store\n        # @return [Integer, String] the +HSET+ reply (HASH index) or the +JSON.SET+ reply (JSON index)\n        # @raise [Redis::CommandError] if a value for a {NumericField} is not Numeric, or the write fails\n        def add(doc_id, **fields)\n          key = @prefix ? \"#{@prefix}#{doc_id}\" : doc_id\n\n          # Validate fields\n          fields.each do |field_name, value|\n            field = @schema.field(field_name)\n            if field.is_a?(NumericField) && !value.is_a?(Numeric)\n              raise Redis::CommandError, \"Invalid value for numeric field '#{field_name}': #{value}\"\n            end\n          end\n\n          begin\n            json? ? @redis.json_set(key, \"$\", fields) : @redis.hset(key, fields)\n          rescue Redis::CommandError => error\n            raise Redis::CommandError, \"Error adding document: #{error.message}\"\n          end\n        end\n\n        # Search the index.\n        #\n        # Accepts a {Query} object, a raw query string, or a block evaluated as a {Query}. Keyword\n        # arguments are applied on top of the query before it is sent. Document ids in the result\n        # have the index prefix stripped, so they match the ids passed to {#add}.\n        #\n        # @example with a Query object\n        #   index.search(Redis::Commands::Search::Query.new(\"@title:hello\").paging(0, 10))","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/commands/modules/search/index.rb#L94-L130","documentation":"Error \"Invalid value for numeric field '#{field_name}': #{value}\" thrown in redis/redis-rb.","triggerScenarios":"Thrown at lib/redis/commands/modules/search/index.rb:112 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2ba9010b91dab9e0fde1fbae3a9aae003f8bc307","analyzedAt":"2026-08-23T03:54:57.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}