HI
I am trying to $skip and $limit after $search in the aggregation. Each and every time when I try to increase my skip size the execution time gets longer
Example:
- Skip 10 and limit 10 then execution time is 500ms
- Skip 30 and limit 10 then execution time is 700ms
- Skip 50 and limit 10 then execution time is 900ms
- Skip 800 and limit 10 then execution time is 20Sec
My code:
db.collection.aggregate([
{
$search: {
"index": 'search',
"count": { "type": "total" },
"compound": {
"must": [{
"range": {
"path": "timestamp",
"gte": ISODate('2020-01-01'),
"lte": ISODate()
}
},
{
"text": {
"query": '(.*)info(.*)',
"path": ['field1', 'field2']
},
},
{
"near": {
"path": 'timestamp',
"origin": ISODate(),
"pivot": 7776000000
}
}
],
}
}
},
{ $skip: 10 },
{ $limit: 10 }
])
I need to know if is there any other way to optimise the query to get faster and if is there any way to specify ascending or descending order in the Atlas search index.