{"record":{"id":"e892f260dda3af77","repo":"redis/redis-rb","slug":"error-adding-document-error-message","errorCode":null,"errorMessage":"Error adding document: #{error.message}","messagePattern":"Error adding document: #(.+?)","errorType":"exception","errorClass":"Redis::CommandError","httpStatus":null,"severity":"error","filePath":"lib/redis/commands/modules/search/index.rb","lineNumber":119,"sourceCode":"        # @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))\n        #\n        # @example with a block\n        #   index.search { text(:title).match(\"hello*\") }\n        #\n        # @param query [Query, String, nil] the query (a {Query}, a query string, or nil when a\n        #   block is given)\n        # @param query_params [Hash, Array, nil] query parameter substitutions (overrides +params+)","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/redis/redis-rb/blob/2ba9010b91dab9e0fde1fbae3a9aae003f8bc307/lib/redis/commands/modules/search/index.rb#L101-L137","documentation":"Error \"Error adding document: #{error.message}\" thrown in redis/redis-rb.","triggerScenarios":"Thrown at lib/redis/commands/modules/search/index.rb:119 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped error message to find the underlying cause (schema mismatch, duplicate id, invalid field) and fix the document or schema accordingly.","Verify every field in the document matches the index schema definition (type and name)."],"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"}