2

I'm using elasticsearch to serve people when they are using dropdown. So far, so good. Right now I'm trying to figure out is it possible to search from different types with different sorts/filters/limits.

So far I've found my way out with different filters per type and kinda with sorts. I've achieved different filters with boolean query, using shoulds and sorting is depending on scores. My goal is to show total 10 rows, where 8 of then should be products, 2 rows should be categories. For categories this limit should be max, if there is no categories to display, 10 products should be displayed. I've read the docs and I can see that size can be set to query body like sorting. But sorting has more flexibility. So yes, question is about the limit - is there a way to achieve it?

4

1 回答 1

1

您要求的似乎是字段折叠或分组。

在 Elasticsearch 问题跟踪器上有一个长期未解决的问题单:https ://github.com/elasticsearch/elasticsearch/issues/256 ,最新更新是(来自http://www.elasticsearch.com/blog/ from-amsterdam-with-love-elasticsearchs-second-company-all-hands/)虽然正在取得进展,但在 1.0 发布之前不会出现:

我们再次充实了在分布式环境执行中正确支持字段折叠所需的内容,以及获得内部命中的能力(对于嵌套/父子案例)。我们对搜索执行基础设施中需要的重构类型有一个很好的想法,并希望在 1.0 之后解决它。

在添加此功能之前,您最好的选择是使用Damien建议的多搜索 api执行多个搜索并以您想要的方式组合它们的结果。这意味着为每个所需组构建一个搜索请求(在您的情况下,为每个搜索设置索引/类型)并解析返回的 JSON 排序。

于 2013-12-09T10:12:26.380 回答