【发布时间】:2017-02-14 17:32:55
【问题描述】:
我有时间序列数据,我想使用具有固定 2000 条记录集的时间范围来查询 Elasticsearch。
我有这个问题
GET http://IP:9200/MYINDEX/_search
{
"_source": ["XXX1", "XXX2","timestamp"],
"sort" :
{ "@timestamp" : {"order" : "asc"}},
"query" : {
"range" : {
"@timestamp" : {
"gte" : "2017-02-10T10:55:31,259Z",
"lte" : "2017-02-10T10:55:32,272Z"
}
}
}
是否可以只返回每 5 条或 10 条记录? 我找到了一些过滤器脚本,但它们似乎都不起作用。
由于一个索引中可能有数百万条记录,因此限制返回值的数量至关重要!
编辑:返工查询,因为过滤已被布尔替换:
{
"_source":[
"XXX1",
"XXX2",
"timestamp"
],
"sort":{
"@timestamp":{
"order":"asc"
}
},
"query":{
"bool":{
"must":{
"range":{
"@timestamp":{
"gte":"2017-02-10T10:55:31,259Z",
"lte":"2017-02-10T10:55:32,272Z"
}
}
},
"filter":{
"script":{
"script":"doc['@timestamp'].value % 5 == 0"
}
}
}
}
}
【问题讨论】:
标签: elasticsearch