我的檔案如下所示:
{
"uri" : "post:1130a8ef197882bc3ebd",
"topic_list" : [
"bye",
"hello"
],
"datetime" : "2010-06-06T22:08:49"
}
我想進行查詢以匯總datetime和topic_list。我想要的輸出是告訴我,在每個時間間隔內,有多少個檔案hello在topic_list.
我試過的是這樣的:
{
"size": 0,
"aggs": {
"test": {
"terms": {
"field": "topic_list"
}
}
}
}
但是輸出只是告訴我有多少檔案始終包含每個主題,而不是在間隔中。我怎樣才能創建這樣的聚合?
uj5u.com熱心網友回復:
您還需要添加兩件事:
- 僅將結果限制為包含主題“hello”的檔案的查詢。如果您只對每個時間間隔的檔案計數感興趣,則不需要欄位
terms上的聚合topic_list - 創建時間間隔的
date_histogram聚合
這是查詢:
{
"size": 0,
"query": {
"term": {
"topic_list": "hello"
}
},
"aggs": {
"intervals": {
"date_histogram": {
"field": "date",
"calendar_interval": "1d"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/468537.html
