您是指例如:过去 7 天、14 天、21 天更新的项目数量?
如果是这样,请使用范围方面:
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