I use elasticsearch, just installed globalize gem (https://github.com/globalize/globalize#i18n-fallbacks-for-empty-translations) with OneIndexPerLanguage class included and I have the following Product model:
class Product < ActiveRecord::Base
translates :product, :product_name, :description, :specification
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
include Elasticsearch::Model::Globalize::OneIndexPerLanguage
settings index: { number_of_shards: 1 } do
mappings dynamic: 'false' do
indexes :product, analyzer: 'czech'
indexes :product_name, analyzer: 'czech'
indexes :manufacturer, analyzer: 'czech'
end
end
globalized_mapping do |locale|
analyzer = locale == :cs ? 'czech' : 'english'
indexes :id, type: 'integer'
indexes :product_name, analyzer: analyzer
indexes :product, analyzer: analyzer
indexes :description, analyzer: analyzer
indexes :specification, analyzer: analyzer
end
def as_indexed_json(options={})
as_json(
only: [:id, :product_name, :product, :manufacturer],
include: { supplier: { only: :name }
})
end
end
What I am trying to figure out and understand, unfortunately with no success yet are the following points:
How can I import values from model attributes (product, product_name, description, specification) to available locales(cs and en)? I tried "Product.import" to update elasticsearch, and it was indexing few of the products, but then I got error (I guess the reason is the translation does not exist):
FAILED (4 prior attempts) with Elasticsearch::Transport::Transport::Errors::NotFound: [404] {"error":"DocumentMissingException[[cs-products][1] [cs-product][1807]: document missing]","status":404}
I have a delayed job run once a day to update these attributes on my model, how can I tell application to not change or update localized versions (ie. cs and en), but only the model values and keep the model values just as a master and for users show by default cs localized version?
- Can I say application, use my Model copies if translations are empty or does not exist for available locales?
Thanks a lot for helping me better understand these features. Miroslav