[英]ElasticSearch + Tire how to force term to return same value as in field
I have list of countries and I whant users be able to sort results by county. 我有国家列表,我希望用户能够按县对结果进行排序。 So I have this helper: 所以我有这个帮手:
def facets_for model, field
ul = ""
links = ""
model.facets[field]['terms'].each do |facet|
links << content_tag('li') do
link_to("#{facet['term']} #{facet['count']}", params.merge(field => facet['term']))
end
end
ul << content_tag("ul", class: field) do
links.html_safe
end
ul.html_safe
end 结束
and in model: 并在模型中:
class model
....
mapping do
indexes :country do
indexes :name, :type => :string, index: "not_analyzed"
end
end
def self.search params
...
filter :term, destination: params[:destination] if params[:destination].present?
facet("destination") { terms 'country.name' }
...
end
but 但
facet['term'] 面[“术语”]
always return country name in lowercase. 始终以小写形式返回国家/地区名称。 I could make it with Country.find(facet).name but I think it is unnecessary. 我可以使用Country.find(facet).name做到这一点,但我认为这是不必要的。 Is there any way to store in facet same string value as in field? 有什么办法可以存储与字段中相同的字符串值?
Updated 更新
my mapping: 我的映射:
{
"wishes" : {
"wish" : {
"properties" : {
"body" : {
"type" : "string"
},
"country" : {
"properties" : {
"name" : {
"type" : "string"
}
}
},
"country_id" : {
"type" : "string"
},
"created_at" : {
"type" : "date",
"format" : "dateOptionalTime"
}
} ... }}}
Your mapping is not created right, you can try to reindex your data. 您的映射创建不正确,您可以尝试重新索引数据。
Model.index.delete # to delete index with bad mapping
Model.create_elasticsearch_index # this should create index with mapping defined in Model
And after that you can try to run Model.import
again. 之后,您可以尝试再次运行Model.import
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.