简体   繁体   English

ElasticSearch小平面滚动周(导轨/轮胎)

[英]ElasticSearch facet rolling weeks (rails / tire)

using ElasticSearch with Rails 3.2.6 (/w Tire) I have a facet on my Project object which displays currently which month the project was posted in: 在Rails 3.2.6中使用ElasticSearch(/ w Tire),我的Project对象上有一个构面,该构面当前显示该项目发布在哪个月:

facet('timeline') { date :post_date, :interval => 'month' }

This gives me the projects grouped in calendar months. 这给了我按日历月分组的项目。 Have also tried 'week' instead of 'month', but this gives me grouped by calendar week. 还尝试了“周”而不是“月”,但这使我可以按日历周分组。 Ideally, what we are looking to do is have rolling groups like this: 理想情况下,我们希望做的是像这样的滚动小组:

  • last 7 days 最近7天
  • last 14 days 最近14天
  • last 21 days 最近21天

Any suggestions on how this can be achieved so that we are not limited to calendar weeks and can easily pick out the relevant buckets from the data?? 关于如何实现此目标的任何建议,使我们不仅限于日历周,而且可以轻松地从数据中选择相关的存储桶? Many thanks 非常感谢

Do you mean for example: the number of projects that have been updated in the previous 7 days, 14 days, 21 days? 例如,您的意思是:在过去7天,14天,21天中已更新的项目数?

If so, use a range facet : 如果是这样,请使用一个范围构面

curl -XGET 'http://127.0.0.1:9200/YOUR_INDEX/project/_search?pretty=1'  -d '
{
   "query" : {
      "match_all" : {}
   },
   "facets" : {
      "projects" : {
         "range" : {
            "ranges" : [
               {
                  "to" : "2012-07-09"
               },
               {
                  "to" : "2012-07-02"
               }
            ],
            "field" : "last_modified_date"
         }
      }
   }
}
'

It would be useful to use date math , eg: 使用日期数学将很有用,例如:

curl -XGET 'http://127.0.0.1:9200/_search?pretty=1&search_type=count'  -d '
{
   "query" : {
      "match_all" : {}
   },
   "facets" : {
      "created" : {
         "range" : {
            "ranges" : [
               {
                  "to" : "now-7d"
               },
               {
                  "to" : "now-14d"
               }
            ],
            "field" : "created"
         }
      }
   }
}
'

but that is not yet supported. 但这尚不支持。 I have opened an issue to request it: https://github.com/elasticsearch/elasticsearch/issues/2102 我已经打开了一个问题来要求它: https : //github.com/elasticsearch/elasticsearch/issues/2102

您可以改用Range Facets ,在那里您将完全控制将要使用的组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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