[英]Group by entire field value in Tire/ElasticSearch
I'm using the Tire rubygem to connect to ElasticSearch. 我正在使用Tire rubygem连接到ElasticSearch。 How can you return facets based on a particular field's value? 如何根据特定字段的值返回构面?
For example, I have a field areas
, and I'd like to show the top 10 areas as filter options: 例如,我有一个领域areas
,我想显示前10个区域作为过滤器选项:
Areas 地区
def self.search(params={}) tire.search(page: 1 || params[:page], per_page: 10, load: true) do # Set up query query do boolean do must { string params[:query], default_operator: "AND" } if params[:query].present? must { range :price, { gte: (params[:min_price] || 0), lte: params[:max_price] } } if params[:max_price].present? end end # Facets to return # this is where I get stuck: facet 'areas' do terms [:area_name], size: 10 end end end
The facet block just returns: facet块仅返回:
{"areas"=>{"_type"=>"terms", "missing"=>5754, "total"=>0, "other"=>0, "terms"=>[]}}
Even though all of the records have a value for area name. 即使所有记录的区域名称都有一个值。
Facets are computed from the documents returned by a query, so if you don't get any hits, no facets are computed. 方面是根据查询返回的文档计算得出的,因此,如果您未获得任何匹配,则不会计算任何方面。 Your facet definition is incorrect, you should pass the field name as a Symbol or String, see https://github.com/karmi/tire/blob/master/test/integration/facets_test.rb#L16 . 您的方面定义不正确,应将字段名称作为符号或字符串传递,请参阅https://github.com/karmi/tire/blob/master/test/integration/facets_test.rb#L16 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.