ankane/searchkick · error · TypeError

can't cast #{value.class.name}

Error message

can't cast #{value.class.name}

What it means

Error "can't cast #{value.class.name}" thrown in ankane/searchkick.

Source

Thrown at lib/searchkick/query.rb:1287

        if source.start_with?("\\A")
          source = source[2..-1]
        else
          source = ".*#{source}"
        end

        if source.end_with?("\\z")
          source = source[0..-3]
        else
          source = "#{source}.*"
        end

        {regexp: {field => {value: source, flags: "NONE", case_insensitive: value.casefold?}}}
      else
        # TODO add this for other values
        if value.as_json.is_a?(Enumerable)
          # query will fail, but this is better
          # same message as Active Record
          raise TypeError, "can't cast #{value.class.name}"
        end

        {term: {field => {value: value}}}
      end
    end

    def custom_filter(field, value, factor)
      {
        filter: where_filters(field => value),
        weight: factor
      }
    end

    def boost_filter(field, factor: 1, modifier: nil, missing: nil)
      script_score = {
        field_value_factor: {
          field: field,
          factor: factor.to_f,

View on GitHub (pinned to 93e901a75b)

When it happens

Trigger: Thrown at lib/searchkick/query.rb:1287 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ankane/searchkick@93e901a75b (2026-08-21). Data as JSON: /api/errors/eca8d2d0dfc670b3. Report an issue: GitHub.