[英]Elasticsearch php : aggregations of documents with date interval
我正在嘗試使用Elasticsearch-php 6.0構建多面搜索,但是我很難弄清楚如何使用日期范圍聚合。 這是我想做的事情:
映射樣本:
"mappings": {
"_doc": {
"properties": {
...
"timeframe": {
"properties": {
"gte": {
"type": "date",
"format": "yyyy"
},
"lte": {
"type": "date",
"format": "yyyy"
}
}
}
...
在我的文檔中,我具有以下屬性:
"timeframe":[{"gte":"1701","lte":"1800"}]
我希望能夠使用日期范圍滑塊顯示構面,用戶可以在其中輸入范圍(最小值-最大值)。 理想情況下,給定當前查詢,Elasticsearch聚合應自動返回這些最小-最大值。
這是我嘗試用“偽代碼”編寫的匯總,以使您有所了解:
"aggs": {
"date_range": {
"field": "timeframe",
"format": "yyyy",
"ranges": [{
"from": min(timeframe.gte),
"to": max(timeframe.lte)
}]
}
}
我想我需要使用日期范圍聚合,最小/最大聚合和管道聚合,但是我對它們的了解越多,我就越困惑。 我找不到如何將整個世界粘合在一起的方法。
請記住,如果這不是實現此目的的正確方法,則可以更改映射和/或文檔結構。
謝謝 !
對於ES本身的官方“ elasticsearch / elasticsearch”軟件包,我可以在此文檔中找到我所需的一系列文檔。 您需要閱讀文檔,因為您需要格式。
$from_date = '2018-03-08T17:58:03Z';
$to_date = '2018-04-08T17:58:03Z';
$params = [
'index' => 'your_index',
'type' => 'your_type',
'body' => [
'query' => [
'range' => [
'my_date_field' => [
//gte = great than or equal, lte = less than or equal
'gte' => $from_date,
// 'lte' => $to_date,
'format' => "yyyy-MM-dd||yyyy-MM-dd'T'HH:mm:ss'Z'",
'boost' => 2.0
]
]
],
]
];
$search = $client->search($params);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.