gpt4 book ai didi

Elasticsearch 自定义聚合结果

转载 作者:行者123 更新时间:2023-12-03 01:55:51 24 4
gpt4 key购买 nike

在我开发的培训模块中,有一个页面将所有类(class)列出到带有可过滤标题的表格 View 中。其中一列是“已保存”列,如果我将其添加为书签,则该列将是“已保存”,否则将是“未保存”。

类(class)实体索引如下:

{
"_index": "myindex",
"_type": "course",
"_id": "248fc0a2-06e1-11e6-b740-000c298fdb4d",
"_score": 1,
"_source": {
"boost_number": 1,
"entity_type_number": 64,
"course_status_string": "Closed",
"title": "My Test Course",
"body": "This is just a test course",
"created_date": "20160420T101753Z",
"categories_uuid": [ ],
"segment_string": [
"Other"
],
"vertical_string": [
"Other"
],
"saved_users_uuid": [
"251bde26-4adf-11e4-b705-000c298fdb4d",
"00026884-7cc8-11e3-a570-fa163e2bcb7a",
"00061164-9283-11e5-a394-000c298fdb4d",
"00110a72-0b8b-11e4-9a64-fa163e2bcb7a",
]
}

假设我使用 id 登录:“251bde26-4adf-11e4-b705-000c298fdb4d”。
在查询弹性方面时,我收到了这个桶:
"saved_users" : {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets" : [
{
"key" : "251bde26-4adf-11e4-b705-000c298fdb4d",
"doc_count" : 5
},
{
"key" : "00026884-7cc8-11e3-a570-fa163e2bcb7a",
"doc_count" : 0
},
...
]
}

但是,我想要另一个自定义存储桶,例如:
{
...
"buckets": [
{
"key": "Saved",
"doc_count": ...
},
{
"key": "Unsaved",
"doc_count": ...
},
]
}

那可能吗?我怎么能那样做?

最佳答案

您可以尝试添加以下 filters aggregation :

{
"size": 0,
"aggs": {
"category": {
"filters": {
"filters": {
"Saved": {
"exists": {
"field": "saved_users_uuid"
}
},
"Unsaved": {
"missing": {
"field": "saved_users_uuid"
}
}
}
}
}
}
}

关于Elasticsearch 自定义聚合结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36835460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com