I'm using the searchkick gem in a Rails app to access Elasticsearch data. I use the aggregations feature to display a histogram on price; the relevant part of the body_options looks like this:
price: {
histogram: {
field: :low_rate,
interval: 50
}
}
The issue I'm having is that I also need to be able to provide a filter on low_rate. So, for example, if I initially have a histogram that has a range of rates between $50 and $500, and I add to the next query where low_rate < 300
, the histogram buckets are recalculated and the chart is entirely redrawn. But in my app I need the chart to still show the same buckets.
This is a pretty common behavior on filters -- see the example below from Airbnb's site, which shows the chart after the upper limit being dragged down -- and so I'm hoping someone might be able to provide some advice about how to achieve this using searchkick.
I can help you with ES Query if it helps.
{
"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
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.