redis/redis-rb · error · Redis::CommandError

Error adding document: #{error.message}

Error message

Error adding document: #{error.message}

What it means

Error "Error adding document: #{error.message}" thrown in redis/redis-rb.

Source

Thrown at lib/redis/commands/modules/search/index.rb:119

        # @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))
        #
        # @example with a block
        #   index.search { text(:title).match("hello*") }
        #
        # @param query [Query, String, nil] the query (a {Query}, a query string, or nil when a
        #   block is given)
        # @param query_params [Hash, Array, nil] query parameter substitutions (overrides +params+)

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Inspect the wrapped error message to find the underlying cause (schema mismatch, duplicate id, invalid field) and fix the document or schema accordingly.
  2. Verify every field in the document matches the index schema definition (type and name).

When it happens

Trigger: Thrown at lib/redis/commands/modules/search/index.rb:119 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/e892f260dda3af77. Report an issue: GitHub.