【发布时间】:2017-10-05 11:59:27
【问题描述】:
我正在尝试使用 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) 我想按 _score 排序,所以我尝试使用
"order": {"_score": "desc"}
返回
"type": "aggregation_execution_exception",
"reason": "Invalid term-aggregator order path [_score]. Unknown aggregation [_score]"
2) 另外,我正在尝试使用分页 - “大小”键实际上可以工作,但“来自”键不会
**UPDATE - 聚合示例结果**
{
"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
}
}
]
}
}
}
]
}
}
}
希望有人能帮忙
【问题讨论】:
-
您在
terms聚合中使用“订单”,这是不允许的。您要对哪些文档应用排序。你能提供示例输出吗? -
@Richa ,因为这里是允许的elastic.co/guide/en/elasticsearch/reference/current/…
-
我的意思是“按_score排序”..抱歉评论不完整。重申我的问题。您要对哪些文档应用排序。你能提供示例输出吗?
-
@Richa,添加聚合的示例结果,希望你所要求的
-
你的意思是你想按分数降序排列你的热门歌曲。如果我错了,请纠正我
标签: javascript node.js elasticsearch indexing nosql