【发布时间】:2021-04-19 13:03:37
【问题描述】:
我想在我的弹性搜索索引中查询类似于以下 postgres 上的查询
select count(distinct(candidate_id)) from candidate_ranking cr
where badge='1'
请考虑以下作为样本索引,文档很少
{
"id": 295537,
"candidate_id": 29492,
"created_at": "2021-03-30T02:23:42.077149+00:00",
"badge": "1"
}
{
"id": 271179,
"candidate_id": 29492,
"created_at": "2021-03-30T01:19:59.803999+00:00",
"badge": "1"
}
{
"id": 247169,
"candidate_id": 29492,
"created_at": "2021-03-30T00:16:04.077245+00:00",
"badge": "1"
}
{
"id": 247156,
"candidate_id": 29332,
"created_at": "2021-03-30T00:17:04.077245+00:00",
"badge": "1"
}
{
"id": 225434,
"candidate_id": 24493,
"created_at": "2021-03-29T23:13:59.266074+00:00",
"badge": null
}
{
"id": 192999,
"candidate_id": 24493,
"created_at": "2021-03-29T22:20:24.942116+00:00",
"badge": null
}
{
"id": 177712,
"candidate_id": 24493,
"created_at": "2021-03-29T21:33:32.596613+00:00",
"badge": null
}
{
"id": 162916,
"candidate_id": 24493,
"created_at": "2021-03-29T21:05:03.985032+00:00",
"badge": null
}
{
"id": 148136,
"candidate_id": 23422,
"created_at": "2021-03-29T20:20:36.482066+00:00",
"badge": "2"
}
{
"id": 118558,
"candidate_id": 23422,
"created_at": "2021-03-27T01:34:29.628550+00:00",
"badge": "2"
}
{
"id": 133354,
"candidate_id": 23422,
"created_at": "2021-03-27T02:11:35.811420+00:00",
"badge": "2"
}
对于上述情况,我的答案计数应为 2,因为 Candidate_id=29492, 29332 的徽章为 1。我的 es 索引包含许多具有相同 Candidate_id 但 created_at 字段不同的文档
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation