redis/redis-rb · error · ArgumentError

schema must be a Schema object

Error message

schema must be a Schema object

What it means

Error "schema must be a Schema object" thrown in redis/redis-rb.

Source

Thrown at lib/redis/commands/modules/search/miscellaneous.rb:44

      # @param max_text_fields [Boolean] emit +MAXTEXTFIELDS+
      # @param skip_initial_scan [Boolean] emit +SKIPINITIALSCAN+ (do not backfill existing keys)
      # @param definition [Search::IndexDefinition, nil] a prebuilt +ON .../PREFIX/FILTER/...+ clause;
      #   when given it takes precedence over +storage_type+/+prefix+
      # @param temporary [Integer, nil] index lifetime in seconds (emits +TEMPORARY <seconds>+)
      # @param no_term_offsets [Boolean] emit +NOOFFSETS+
      # @param no_highlight [Boolean] emit +NOHL+
      # @param no_field_flags [Boolean] emit +NOFIELDS+
      # @param no_term_frequencies [Boolean] emit +NOFREQS+
      # @return [String] +"OK"+
      # @raise [ArgumentError] if +schema+ is not a {Search::Schema}
      def ft_create(
        index_name, schema, storage_type = nil,
        prefix: nil, stopwords: nil, max_text_fields: false,
        skip_initial_scan: false, definition: nil, temporary: nil,
        no_term_offsets: false, no_highlight: false,
        no_field_flags: false, no_term_frequencies: false, **_options
      )
        raise ArgumentError, "schema must be a Schema object" unless schema.is_a?(Schema)

        args = [index_name]

        # Use IndexDefinition if provided, otherwise use legacy parameters
        if definition
          # The definition supplies the ON/PREFIX/FILTER clause. When it doesn't declare an index
          # type, fall back to the storage_type keyword so e.g. a JSON index isn't silently created
          # as HASH. Normalize to the uppercase HASH/JSON form some Query Engine versions require.
          args += ["ON", storage_type.to_s.upcase] if definition.index_type.nil? && storage_type
          args += definition.args
        else
          # Normalize the ON token to HASH/JSON; a lowercase value is rejected by some
          # Query Engine versions (and IndexType/the docs use the uppercase form).
          args += ["ON", storage_type.to_s.upcase] if storage_type
          args += ["PREFIX", 1, "#{prefix}:"] if prefix
        end

        args << "MAXTEXTFIELDS" if max_text_fields

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Pass a Schema object (built via the schema DSL) instead of a hash or array.
  2. Construct the schema first, e.g. Schema.new { |s| s.text_field(:title) }, and pass that instance.

When it happens

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