ElasticSearch – 聚合/分组:通过sorting和分页

我试图使用Elasticsearch(2.4)聚合通过使用该查询多个索引上的“productId”进行分组

{ "from": 0, "size": 0, "min_score": 0.15, "query": { "filtered": { "query": { "bool": { "should": [ { "match_phrase_prefix": { "keywords.family": { "query": "low fat milk", "fuzziness": 0.7, "boost": 5 } } } ] } } } }, "aggs": { "group_by_0": { "terms": { "field": "productId", "size": 50 }, "aggs": { "top_tag_hits": { "top_hits": { "size": 1 } } } } } } 

1)我想按_scoresorting,所以我试过使用

 "order": {"_score": "desc"} 

哪个返回

 "type": "aggregation_execution_exception", "reason": "Invalid term-aggregator order path [_score]. Unknown aggregation [_score]" 

2)另外,我试图使用分页 – “大小”键实际工作,但“从”不会

**更新 – 聚合示例结果**

 { "took": 5108, "timed_out": false, "_shards": { "total": 105, "successful": 105, "failed": 0 }, "hits": { "total": 9963, "max_score": 0, "hits": [] }, "aggregations": { "group_by_0": { "doc_count_error_upper_bound": 69, "sum_other_doc_count": 9779, "buckets": [ { "key": 98761, "doc_count": 36, "top_tag_hits": { "hits": { "total": 36, "max_score": 0.36901662, "hits": [ { "_index": "retailer-1", "_type": "product", "_id": "1409421", "_score": 0.36901662, "_source": { "productId": 98761 } } ] } } }, { "key": 107459, "doc_count": 36, "top_tag_hits": { "hits": { "total": 36, "max_score": 0.42744976, "hits": [ { "_index": "retailer-2", "_type": "product", "_id": "1402563", "_score": 0.42744976, "_source": { "productId": 107459 } } ] } } } ] } } } 

希望有人能帮忙

尝试下面的查询

 { "from": 0, "size": 0, "query": { "filtered": { "query": { "bool": { "should": [ { "match_phrase_prefix": { "keywords.family": { "query": "low fat milk", "fuzziness": 0.7, "boost": 5 } } } ] } } } }, "aggs": { "group_by_0": { "terms": { "field": "productId", "size": 50 }, "aggs": { "top_tag_hits": { "top_hits": { "size": 1, "sort": [ { "_score": { "order": "desc" } } ] } } } } } } 

这将按照分数的降序排列最高点。 对于聚合桶分页,这是不可能的。 可能在更新的版本中获得此function。