gpt4 book ai didi

ElasticSearch如何显示所有匹配日期范围聚合的文档

转载 作者:行者123 更新时间:2023-11-29 02:56:06 28 4
gpt4 key购买 nike

以下弹性文档: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html

问题:

如何进行日期范围聚合并显示与相关日期桶匹配的所有文档,而不是 doc_count

聚合:

{
"aggs" : {
"articles_over_time" : {
"date_histogram" : {
"field" : "date",
"interval" : "1M",
"format" : "yyyy-MM-dd"
}
}
}
}

响应:

        {
"aggregations": {
"articles_over_time": {
"buckets": [
{
"key_as_string": "2013-02-02",
"key": 1328140800000,
"doc_count": 1
},
{
"key_as_string": "2013-03-02",
"key": 1330646400000,
"doc_count": 2 //how display whole json ??

[ .. Here i want to display
all document with array based
NOT only doc_count:2.......... ]

},
...
]
}
}
}

也许我需要做一些子聚合或其他事情?

有什么想法吗?

最佳答案

您必须对 date-histogram 聚合执行 top_hits 子聚合。所有选项都可以从 here 中读取.

你的最终聚合看起来像这样

{
"aggs": {
"articles_over_time": {
"date_histogram": {
"field": "date",
"interval": "1M",
"format": "yyyy-MM-dd"
},
"aggs": {
"documents": {
"top_hits": {
"size": 10
}
}
}
}
}
}

关于ElasticSearch如何显示所有匹配日期范围聚合的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408328/

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