elasticsearch and rails : how to handle multilanguage objet?

Tag: elasticsearch , multilanguage Author: zhuliang2006 Date: 2013-05-18

I m using rails and elasticsearch. My object "product" have a title and a text in different language and also a price and a category

here what im currently doing. it is working, but very slow

mapping do
  indexes :id, type: 'integer', :index    => :not_analyzed
  indexes :sousrubrique_id, type: 'integer', :index    => :not_analyzed
  indexes :price, type: 'float', :index    => :not_analyzed

  Language.get_mapping_langues.each  do |idl, value|
    class_eval <<-RUBY
      indexes :title_#{value}, :as => lambda { |product| product.attributes['title_' + value] unless product.attributes['date_validation_' + value].nil? }
      indexes :text_#{value}, :as => lambda { |product| product.attributes['text_' + value] unless product.attributes['date_validation_' + value].nil?}

tire.search(:page => (prms[:page] || 1)) do
  query do
    filtered {
      query { string mc} unless mc.blank?
      filter :term, :sousrubrique_id => prms[:sousrubrique_id] unless prms[:sousrubrique_id].blank?
      filter :range, {:prix_local_objet => {:from => prms[:price][:max], :to => prms[:price][:min]}}

but when I make a search, then it will search in all language, when actually I would like only for the current language, which should be quicklier.

is there a way to do that ? Or should I create one index for each language ? But if such, how to tell which index to use for callback when I delete or edit or create a product ?