redis/redis-rb · error · ArgumentError

Invalid query

Error message

Invalid query

What it means

Error "Invalid query" thrown in redis/redis-rb.

Source

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

        # @param highlight [Hash, nil] +HIGHLIGHT+ options
        # @param sort_by [String, nil] sort field (+SORTBY+)
        # @param asc [Boolean, nil] sort ascending (default) when +sort_by+ is given; +false+ for descending
        # @param scorer [String, nil] scoring function name (+SCORER+)
        # @param explain_score [Boolean, nil] include a score explanation (+EXPLAINSCORE+)
        # @return [SearchResult] the total count and matching {Document}s (prefix stripped from ids)
        # @raise [ArgumentError] if no usable query is provided
        def search(query = nil, query_params: nil, params: nil, dialect: nil,
                   nocontent: nil, verbatim: nil, no_stopwords: nil, with_scores: nil,
                   with_payloads: nil, slop: nil, in_order: nil, language: nil,
                   return_fields: nil, summarize: nil, highlight: nil, sort_by: nil, asc: nil,
                   scorer: nil, explain_score: nil, &block)
          if block_given?
            query = Query.build(&block)
          elsif query.is_a?(String)
            query = Query.new(query)
          end

          raise ArgumentError, "Invalid query" unless query.is_a?(Query)

          query_string = query.to_redis_args.first

          sort_order = asc == false ? "DESC" : "ASC"
          sortby = sort_by ? [sort_by, sort_order] : query.options[:sortby]
          limit_ids = query.limit_ids_value
          # INKEYS needs full Redis keys. Prepend the index prefix to logical ids (mirroring
          # #add), but leave ids that already carry it alone so callers passing full keys don't
          # get a doubled prefix that matches nothing.
          if limit_ids && @prefix
            limit_ids = limit_ids.map { |id| id.to_s.start_with?(@prefix) ? id : "#{@prefix}#{id}" }
          end

          # An empty RETURN list is not a meaningful per-call value (it would just omit RETURN and
          # return all fields), so treat it as "unset" and fall back to the Query's RETURN list.
          return_fields = nil if return_fields.is_a?(Array) && return_fields.empty?

          # Build a fresh options hash per call. A per-call keyword argument wins when explicitly

View on GitHub (pinned to 2ba9010b91)

Solutions

  1. Pass a valid query string or query object to the search call; empty or malformed query syntax is rejected.
  2. Validate the query syntax against RediSearch query rules before calling search.

When it happens

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