简体   繁体   English

带有聚合的 Searchkick (Elasticsearch) 直方图 - 扩展边界

[英]Searchkick (Elasticsearch) histogram with aggregations - extending bounds

I'm using the searchkick gem in a Rails app to access Elasticsearch data.我在 Rails 应用程序中使用 searchkick gem 来访问 Elasticsearch 数据。 I use the aggregations feature to display a histogram on price;我使用聚合功能来显示价格的直方图; the relevant part of the body_options looks like this: body_options 的相关部分如下所示:

            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.我遇到的问题是我还需要能够提供一个关于 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.因此,例如,如果我最初有一个直方图,其费率范围在 50 美元到 500 美元之间,并且我添加到下一个查询where low_rate < 300 ,则重新计算直方图桶并完全重新绘制图表。 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.这是过滤器上非常常见的行为——请参阅下面来自 Airbnb 网站的示例,该示例显示了上限被下拉后的图表——所以我希望有人能够提供一些有关如何实现这一目标的建议使用搜索踢。

直方图行为示例

I can help you with ES Query if it helps.如果有帮助,我可以帮助您使用 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM