elasticsearch - elasticsearch 中的 sql count(dictinct())) 等价物是什么?
问题描述
我想问一下 elasticsearch 中的 sql count(dictinct())) 是什么?我的意思是如何使以下 sql 查询成为 elasticsearch 查询。我尝试了一些聚合,但我没有找到确切的答案。
select count(distinct(unique_field)) where db_date < "..." and db_date > "..."
我已经尝试了下面的代码,但它没有通过 sql 给出预期的结果。
{
"query": {
"bool": {
"must": [
{
"term": {
"city": {
"value": "bratislava"
}
}
},
{
"range": {
"db_date": {
"gte": "2020-05-15T00:00:00.000Z",
"lte": "2020-05-16T00:00:00.000Z"
}
}
}
]
}
},
"aggs": {
"types_count": {
"value_count": {
"field": "unique_field"
}
},
"group_by_status": {
"terms": {
"field": "unique_field"
}
}
}
}
谢谢回答
解决方案
推荐阅读
- css - 词缀打破了引导程序的嵌套网格
- android - 如何使用 Kotlin 将我计算机中托管的 MySQL 连接到 Android 应用程序
- android - 无法获取 Google 依赖项 PKIX 路径构建失败
- sql - 分组数据的 SQL 查询
- c++ - 我需要在这里显式调用析构函数吗?
- azure - 通过流分析的条件在 sql 表中插入/更新来自 iothub 的引用数据
- angular - 在内联编辑功能Angular 4期间反映更新的值变化 -
- r - 使用R将列作为字符转换为列表类型
- php - WordPress 中 Twig / Timber 的转义要求
- sql - Node 中的辅助 SQL 函数