ankane/searchkick · error · Searchkick::Error

Search synonyms are not supported yet for language

Error message

Search synonyms are not supported yet for language

What it means

Search-synonyms (`search_synonyms:`) are implemented by inserting a `searchkick_synonym_graph` filter into existing query analyzers (`searchkick_search2`, `searchkick_word_search`). For languages other than japanese/japanese2, those analyzers must already declare a `:filter` array in the settings; if the chosen `language:` produced analyzers without one, searchkick raises `Error` because there is nothing to insert the graph filter into. This happens at index build (reindex) time.

Source

Thrown at lib/searchkick/index_options.rb:620

            updateable: true
          }
        else
          synonym_graph = {
            type: "synonym_graph",
            # TODO confirm this is correct
            synonyms: search_synonyms.select { |s| s.size > 1 }.map { |s| s.is_a?(Array) ? s.join(",") : s }.map(&:downcase)
          }
        end
        settings[:analysis][:filter][:searchkick_synonym_graph] = synonym_graph

        if ["japanese", "japanese2"].include?(options[:language])
          [:searchkick_search, :searchkick_search2].each do |analyzer|
            settings[:analysis][:analyzer][analyzer][:filter].insert(4, "searchkick_synonym_graph")
          end
        else
          [:searchkick_search2, :searchkick_word_search].each do |analyzer|
            unless settings[:analysis][:analyzer][analyzer].key?(:filter)
              raise Error, "Search synonyms are not supported yet for language"
            end

            settings[:analysis][:analyzer][analyzer][:filter].insert(2, "searchkick_synonym_graph")
          end
        end
      end
    end

    def set_deep_paging(settings)
      if !settings.dig(:index, :max_result_window) && !settings[:"index.max_result_window"]
        settings[:index] ||= {}
        settings[:index][:max_result_window] = options[:max_result_window] || 1_000_000_000
      end
    end

    def index_type
      @index_type ||= begin
        index_type = options[:_type]

View on GitHub (pinned to 93e901a75b)

Solutions

  1. Test with plain `synonyms:` instead of `search_synonyms:` — plain synonyms use the index-time synonym filter and work for all languages.
  2. Check the release notes / source for which languages support `search_synonyms` in your searchkick version and stick to those (english and japanese/japanese2 are the known-good paths).
  3. Define custom analyzers with explicit `filter:` arrays via the `settings:` option so the graph filter can be inserted.
  4. Drop the `language:` option (default analyzers have filters) if English-style analysis is acceptable for that index.

Example fix

# before
class Product < ApplicationRecord
  searchkick language: "german", search_synonyms: [["bett", "lager"], ["sofa", "couch"]]
end
Product.reindex # => Searchkick::Error: Search synonyms are not supported yet for language

# after
class Product < ApplicationRecord
  searchkick language: "german", synonyms: [["bett", "lager"], ["sofa", "couch"]]
end
Product.reindex
Defensive patterns

Strategy: validation

Validate before calling

language = "german"
search_synonyms = [["bett", "lager"]]
if search_synonyms && !%w[english japanese japanese2].include?(language.to_s)
  Searchkick.warn "search_synonyms unsupported for #{language}; falling back to index-time synonyms"
  search_synonyms = nil
end
class Product < ApplicationRecord
  searchkick language: language, synonyms: [["bett", "lager"]]
end

Type guard

def search_synonyms_supported?(language)
  %w[english japanese japanese2].include?(language.to_s)
end

Try / catch

begin
  Product.reindex
rescue Searchkick::Error => e
  raise unless e.message.include?("Search synonyms are not supported")
  # fall back: drop search_synonyms, use index-time synonyms, then retry
  Product.searchkick_index.delete
  retry
end

Prevention

When it happens

Trigger: `searchkick language: "german" (or italian, french, etc.), search_synonyms: [...]` followed by `Model.reindex`. Languages that use the prebuilt analyzer with filters are fine; the raise fires when `settings[:analysis][:analyzer][analyzer]` has no `:filter` key for `searchkick_search2` or `searchkick_word_search`.

Common situations: Enabling `search_synonyms` on a non-English/non-Japanese language index; upgrading searchkick and adding synonyms to an existing localized index; using `language:` values whose analyzer templates changed between searchkick versions.

Related errors


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