[英]Rails ElasticSearch Tire - filter nested field on multiple parameters the same time
[英]Rails elasticsearch tire nested mapping
我正在尝试将嵌套标签索引到我的产品模型中。 产品索引良好,但与该产品关联的嵌套标签索引不好。 我能怎么做? 我的映射正确吗?
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
谢谢!
好的,我找到了答案:
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
并且无需在映射中包含id,updated_at和created_at,因为它会自动建立索引。 谢谢轮胎!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.