2012-07-16 63 views
0

使用ElasticSearch使用Rails 3.2.6(/ W轮胎) 我有我的项目对象上的面,显示当前哪个月该项目被张贴在:ElasticSearch面滚动周(导轨/轮胎)

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

这给了我在日历月份中分组的项目。也尝试过“周”而不是“月”,但这使我按日历周分组。 理想的情况下,我们所希望做的是有滚动组这样的:

  • 过去7天
  • 过去14天
  • 最后21天

如何这可能是任何建议实现以便我们不限于日历周,并且可以轻松从数据中挑出相关的桶? 非常感谢

回答

3

您的意思是:例如:在过去7天,14天,21天更新的项目数量?

如果是这样,使用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" 
     } 
     } 
    } 
} 
' 

这将是有益的使用date math,如:

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" 
     } 
     } 
    } 
} 
' 

但尚不支持。我已经打开了一个问题,要求它︰ https://github.com/elasticsearch/elasticsearch/issues/2102

+0

嗨,谢谢,它得到它的工作,其实日期计算可以在Rails /轮胎 – bobomoreno 2012-07-17 14:21:35

相关问题