I can get the newest document before a certain timestamp with this query (hopefully with reasonable performance):
{
"query": {
"bool": {
"filter": [
{
"range": {
"timestamp": {
"lt": 1508010043
}
}
}
]
}
},
"sort": {
"timestamp": "desc"
},
"size": 1
}
How can I run an aggregation on it?