【发布时间】:2019-09-17 21:20:44
【问题描述】:
我正在从 SQL 迁移到 elasticsearch,但我遇到了一些聚合问题,尤其是 group by
我的查询看起来像
SELECT count(*) as total,country_code
FROM orders
WHERE product_id = ?
GROUP BY country_code
ORDER BY total desc LIMIT 3
这个我试过了,但是不行
{
"query": {
"bool": {
"must": [
{
"match": {
"line_items.product_id": {
"query": "0001112223333"
}
}
}
]
}
},
"from": 0,
"size": 3,
"aggregations": {
"country_code": {
"aggregations": {
"COUNT(*)": {
"value_count": {
"field": "_index"
}
}
},
"terms": {
"field": "country_code",
"size": 200
}
}
}
}
【问题讨论】:
-
“我试过这个但没有用” - 什么不完全有效?
-
@Caramiriel 我刚刚更新了我的问题请查看图片
标签: node.js elasticsearch elasticsearch-aggregation