[英]ElasticSearch: How to aggregate values from nested field with date range?
[英]How to aggregate different field by a date field in Elasticsearch
REST API調用
GET test10/LREmail10/_search/
{
"size": 10,
"query": {
"range": {
"ALARM DATE": {
"gte": "now-15d/d",
"lt": "now/d"
}
}
},
"fields": [
"ALARM DATE",
"CLASSIFICATION"
]
}
投入的一部分是
"took": 25,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 490,
"max_score": 1,
"hits": [
{
"_index": "test10",
"_type": "LREmail10",
"_id": "AVM5g6XaShke4hy5dziK",
"_score": 1,
"fields": {
"CLASSIFICATION": [
"Attack"
],
"ALARM DATE": [
"25/02/2016 8:35:22 AM(UTC-08:00)"
]
}
},
{
"_index": "test10",
"_type": "LREmail10",
"_id": "AVM5g6e_Shke4hy5dziL",
"_score": 1,
"fields": {
"CLASSIFICATION": [
"Compromise"
],
"ALARM DATE": [
"25/02/2016 8:36:16 AM(UTC-08:00)"
]
}
},
我在這里真正想做的是,按ALARM DATE匯總分類。 日期的默認格式也包括分鍾,秒和時區。 但是我想對每個日期進行所有分類。 因此, "25/02/2016 8:36:16 AM(UTC-08:00)"
和"25/02/2016 8:35:22 AM(UTC-08:00)"
應被視為"25/02/2016"
日期。 並獲得所有分類屬於一個日期。
我希望我已經正確解釋了問題。 如果你們需要更多詳細信息,請告訴我。
如果有人的話,可以給我一個提示,看看Elasticsearch中的哪個區域也很有幫助。
使用如下所示的date_histogram 。
{
"size" :0 ,
"aggs": {
"classification of day": {
"date_histogram": {
"field": "ALARM DATE",
"interval": "day"
},
"aggs": {
"classification": {
"terms": {
"field": "CLASSIFICATION"
}
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.