gpt4 book ai didi

elasticsearch - Elasticsearch 聚合查询返回的结果自1970年以来?

转载 作者:行者123 更新时间:2023-12-03 02:30:11 25 4
gpt4 key购买 nike

嗨,我是 Elasticsearch 的新手。我正在运行以下查询/其余请求以进行 Elasticsearch 。我试图获得一年的直方图。但是,结果返回的数据是1970年以来的数据,而不是去年到今年的数据。

curl -X GET "10.10.9.1:9200/mep-reports*/_search?pretty&size=0" -H 'Content-Type: application/json' -d'
{
"query": {

"bool": {

"must": [
{ "range": { "@timestamp": {"gte": "now-1y/y" , "lt": "now"}}}
]
}
},

"aggs" : {
"sales_over_time" : {
"date_histogram" : {
"field" : "submission_ts",
"interval" : "day",
"format": "yyyy-MM-dd hh:mm:ss"
}
}
}

}'

以下是我收到的回复。如果您检查key_as_string,您可以看到它从1970年开始。我的问题是为什么它忽略指定的范围 ( { "range": { "@timestamp": {"gte": "now-1y/y" , "lt": "now"}}})
{
"took" : 22,
"timed_out" : false,
"_shards" : {
"total" : 12,
"successful" : 12,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1073013,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"sales_over_time" : {
"buckets" : [
{
"key_as_string" : "1970-01-19 12:00:00",
"key" : 1555200000,
"doc_count" : 1016510
},
{
"key_as_string" : "1970-01-20 12:00:00",
"key" : 1641600000,
"doc_count" : 0
},
{
"key_as_string" : "1970-01-21 12:00:00",
"key" : 1728000000,
"doc_count" : 0
},
{
"key_as_string" : "1970-01-22 12:00:00",
"key" : 1814400000,
"doc_count" : 0
},
{
"key_as_string" : "1970-01-23 12:00:00",
"key" : 1900800000,
"doc_count" : 0
},
{
"key_as_string" : "1970-01-24 12:00:00",
"key" : 1987200000,
"doc_count" : 0
},
{
"key_as_string" : "1970-01-25 12:00:00",
"key" : 2073600000,
"doc_count" : 0
},
}

最佳答案

您的查询在@timestamp字段上,但您的汇总在submission_ts上。

如果希望date_histogram聚合受查询限制,则需要在查询和聚合中使用相同的字段。

curl -X GET "10.10.9.1:9200/mep-reports*/_search?pretty&size=0" -H 'Content-Type: application/json' -d'
{
"query": {

"bool": {

"must": [
{ "range": { "submission_ts": {"gte": "now-1y/y" , "lt": "now"}}}
]
}
},

"aggs" : {
"sales_over_time" : {
"date_histogram" : {
"field" : "submission_ts",
"interval" : "day",
"format": "yyyy-MM-dd hh:mm:ss"
}
}
}

}'

关于elasticsearch - Elasticsearch 聚合查询返回的结果自1970年以来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60192801/

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