我使用id和name为我的模型颜色编制索引,当使用与Searchkick的聚合时,我需要在结果中包含一个哈希中的id和name,而不是单独的。
如何实现?
这就是现在的工作方式:
查询
2.1.3 :036 > Product.search("slipy", aggs: ['colors.id','colors.name']).aggs
结果
正如您所看到的,ID和名称是单独的哈希值,因此关系被破坏了。
{"colors.name"=>{"doc_count_error_upper_bound"=>0, "sum_other_doc_count"=>0, "buckets"=>[{"key"=>"black", "doc_count"=>149}, {"key"=>"white", "doc_count"=>124}, {"key"=>"blue", "doc_count"=>102}, {"key"=>"red", "doc_count"=>57}, {"key"=>"yellow", "doc_count"=>35}, {"key"=>"grey", "doc_count"=>26}, {"key"=>"turquoise", "doc_count"=>18}, {"key"=>"green", "doc_count"=>17}, {"key"=>"orange", "doc_count"=>8}, {"key"=>"pink", "doc_count"=>8}, {"key"=>"purple", "doc_count"=>3}, {"key"=>"none", "doc_count"=>2}]}, "colors.id"=>{"doc_count_error_upper_bound"=>0, "sum_other_doc_count"=>0, "buckets"=>[{"key"=>2, "doc_count"=>149}, {"key"=>13, "doc_count"=>124}, {"key"=>3, "doc_count"=>102}, {"key"=>4, "doc_count"=>57}, {"key"=>6, "doc_count"=>35}, {"key"=>7, "doc_count"=>26}, {"key"=>10, "doc_count"=>18}, {"key"=>5, "doc_count"=>17}, {"key"=>8, "doc_count"=>8}, {"key"=>9, "doc_count"=>8}, {"key"=>11, "doc_count"=>3}, {"key"=>1, "doc_count"=>2}]}}
这样做的目的是生成各种过滤器,我需要后端ID和前端名称。如果使用searchkick无法做到这一点,那还有其他"解决方法"怎么实现这个?
谢谢你,米罗