Vit*_*mar 7 sorting elasticsearch
我需要value
从每个项目获得最大的项目name
并重复直到结束.
我将在简单的例子中解释它.我有这样的项目:
Name| Value
-----------
AAA | 12
AAA | 35
AAA | 5
BBB | 1
BBB | 10
BBB | 5
Run Code Online (Sandbox Code Playgroud)
排序后的预期结果:
Name| Value
-----------
AAA | 35
BBB | 10
AAA | 12
BBB | 5
AAA | 5
BBB | 1
Run Code Online (Sandbox Code Playgroud)
我知道如何在Postgres中执行此操作(窗口函数:) rank() over()
,但它是否可以在Elastic?
你必须做类似 Group by max 的事情
这是示例
GET /yourindex/_search
{
"size": 0
"aggs": {
"yourGroup": {
"terms": {
"field": "Name",
"size": 10
},
"aggs": {
"theMax": {
"max": {
"field": "Value"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
参考:- 这个