ruby-on-railselasticsearchsearchkick

Implementing one language per field with Searchkick


I'm trying to add multi-language support of a Rails app which uses searchkick for search functionality.

After some research I've decided to go with the one language per field approach as described here. However, after googling for quite a bit, I couldn't find any documentation on this topic in terms of get it implemented with searchkick.

Essentially, I cannot find the way to specify a language analyzer for a given field using searchkick.

Any help would be appreciated.


Solution

  • You have to use custom mapping with language analyzers

    class Product < ApplicationRecord
      searchkick mappings: {
        properties: {
          title_en: {type: "text", analyzer: "english"},
          title_fr: {type: "text", analyzer: "french"},
        }
      }
    end
    

    and probably a custom search query

    products = Product.search body: {query: {match: {title_en: "milk"}}}