弹性搜索分面导航
elasticsearch faceted navigation
我正在尝试创建一个 rails 应用程序,类似于 here on elasticsearch aggregations. I updated it to work with the current elasticsearch 2.3. The javascript works well but the filter returns nothing when I select more that one checkbox. The code different from the app here 不处理复选框的应用程序。我错过了什么?
过滤器看起来像这样:
__set_filters = lambda do |key, f|
@search_definition[:post_filter][:and] ||= []
@search_definition[:post_filter][:and] |= [f]
@search_definition[:aggregations][key.to_sym][:filter][:bool][:must] ||= []
@search_definition[:aggregations][key.to_sym][:filter][:bool][:must] |= [f]
end
if options[:category]
f = { term: { "categories,name" => options[:category] } }
__set_filters.(:location, f)
end
if options[:location]
f = { term: { "location,name" => options[:location] } }
__set_filters.(:categories, f)
end
刚接触 Elastic Search 时,使用过滤器可能会让人头疼,因为它正在为特定字段寻找与您的输入完全匹配的内容,但是当它第一次为事物编制索引时(尤其是使用标准分析器的字符串,如果您没有指定不同的分析器) ) 它将字段拆分为多个字符串,他们的文档将其称为标记。例如,在没有指定分析器的情况下索引名为 "Oyster Bay" 的城镇实际上会将字段分成两个标记 "Oyster" 和 "Bay"。如果您随后尝试在此字段上使用过滤器并输入 "Oyster Bay",它不会将其视为完全匹配,而将其视为 return。如果您计划对查询使用过滤器,我建议您将 "not_analyzed" 索引添加到映射中的相应字段以避免此问题。
我正在尝试创建一个 rails 应用程序,类似于 here on elasticsearch aggregations. I updated it to work with the current elasticsearch 2.3. The javascript works well but the filter returns nothing when I select more that one checkbox. The code different from the app here 不处理复选框的应用程序。我错过了什么?
过滤器看起来像这样:
__set_filters = lambda do |key, f|
@search_definition[:post_filter][:and] ||= []
@search_definition[:post_filter][:and] |= [f]
@search_definition[:aggregations][key.to_sym][:filter][:bool][:must] ||= []
@search_definition[:aggregations][key.to_sym][:filter][:bool][:must] |= [f]
end
if options[:category]
f = { term: { "categories,name" => options[:category] } }
__set_filters.(:location, f)
end
if options[:location]
f = { term: { "location,name" => options[:location] } }
__set_filters.(:categories, f)
end
刚接触 Elastic Search 时,使用过滤器可能会让人头疼,因为它正在为特定字段寻找与您的输入完全匹配的内容,但是当它第一次为事物编制索引时(尤其是使用标准分析器的字符串,如果您没有指定不同的分析器) ) 它将字段拆分为多个字符串,他们的文档将其称为标记。例如,在没有指定分析器的情况下索引名为 "Oyster Bay" 的城镇实际上会将字段分成两个标记 "Oyster" 和 "Bay"。如果您随后尝试在此字段上使用过滤器并输入 "Oyster Bay",它不会将其视为完全匹配,而将其视为 return。如果您计划对查询使用过滤器,我建议您将 "not_analyzed" 索引添加到映射中的相应字段以避免此问题。