I have a query that filters on a date range and term, select N documents starting at from
position 0, and then sorts them. However, I want the sorting to occur just after filtering, before selecting N documents.
My query:
{
'filter': {
'and': [
{
'range': {
'updated_at': {
'lte': 1482652799999,
'gte': 1481961600000
}
}
},
{
'term': {
'name': 'my name'
}
}
]
},
'sort': [
'updated_at',
{
'updated_at': 'desc'
}
],
'size': 3,
'from': 0
}
This query is giving me:
batch 1= [12/17, 12/17, 12/15], and incrementing the "from" value, batch 2= [12/21, 12/20, 12/18],
but I want:
batch 1= [12/21, 12/20, 12/18] and batch 2= [12/17, 12/17, 12/15].
It should apply the sort before filter. Try converting your filter into a query, or at least the term part. It should be executed as query, sort, filter.