Reputation: 565
I'm trying to index nested tags to my product model. The products indexes well but not the nested tags associated to the product. How can i do? is my mapping correct?
Product Class
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :id, type: 'integer', index: :not_analyzed
indexes :name, type: 'string', analyzer: 'snowball', boost: 100
indexes :description, analyzer: 'snowball'
indexes :price, type: 'float'
indexes :category, type: 'string'
indexes :location, type: 'string'
indexes :online, type: 'boolean'
indexes :created_at, type: 'date', index: :not_analyzed
indexes :updated_at, type: 'date', index: :not_analyzed
indexes :tags do
indexes :id, type: 'integer', index: :not_analyzed
indexes :name, type: 'string', analyzer: 'snowball', boost: 100
end
end
def to_indexed_json
{
id: id,
name: name,
description: description,
price: price,
category: category,
location: location,
online: online,
created_at: created_at,
updated_at: updated_at,
include: { tags: { only: [:name] } }
}.to_json
end
Thanks!
Upvotes: 0
Views: 1365
Reputation: 565
ok, i have found the answer:
def to_indexed_json
{
name: name,
description: description,
price: price,
category: category,
location: location,
online: online,
created_at: created_at,
updated_at: updated_at,
tags: tags
}.to_json
end
And no need to include id, updated_at and created_at to the mapping because it's automatically indexed. Thanks Tire!
Upvotes: 1