[英]Searchkick (Elasticsearch) histogram with aggregations - extending bounds
我在 Rails 應用程序中使用 searchkick gem 來訪問 Elasticsearch 數據。 我使用聚合功能來顯示價格的直方圖; body_options 的相關部分如下所示:
price: {
histogram: {
field: :low_rate,
interval: 50
}
}
我遇到的問題是我還需要能夠提供一個關於 low_rate 的過濾器。 因此,例如,如果我最初有一個直方圖,其費率范圍在 50 美元到 500 美元之間,並且我添加到下一個查詢where low_rate < 300
,則重新計算直方圖桶並完全重新繪制圖表。 但在我的應用程序中,我需要圖表仍然顯示相同的桶。
這是過濾器上非常常見的行為——請參閱下面來自 Airbnb 網站的示例,該示例顯示了上限被下拉后的圖表——所以我希望有人能夠提供一些有關如何實現這一目標的建議使用搜索踢。
如果有幫助,我可以幫助您使用 ES 查詢。
{
"size": 0,
"aggs": {
"hist": {
"histogram": {
"field": "low_rate",
"interval": 50,
"extended_bounds": { // <======= It is used to extend bounds
"min": 50, // <========== Specify the min bound
"max": 500 // <========== Specify the max bound
},
"missing":10 // <========== value of the missing docs in the range
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.