[英]Sorting on any field in MongoDb Atlas Search pipeline
I have a test data set (500k rows)我有一个测试数据集(500k 行)
{
"_id": ObjectId("61309575c9346aab086f91fb"),
"listId": ObjectId("61309575c9346aab086f91fa"),
"createdDate": ISODate("2021-09-02T09:12:21.594Z"),
"es0": "Firstname 0 Moscow",
"es1": "firstname0@gmail.com",
"es2": "0701230000",
"es3": "Equatorial Guinea",
"es4": "Iceland",
"es5": "Los Angeles International Airport",
"ed0": ISODate("1975-10-17T00:00:00Z"),
"ed1": ISODate("2020-01-01T00:00:00Z"),
"ei0": 46,
"ei1": 1345
}
I have a test query like this我有这样的测试查询
db.collection.aggregate([{
$search: {
"index": "test_index1",
"compound": {
"filter": [{
"equals": {
"path": "listId",
"value": ObjectId("613098df46239505942b8b13")
}
}],
"must": [{
"text": {
"query": 'Los Angeles',
"path": {
'wildcard': '*'
}
}
}]
}
}
},
{
$limit: 10
}]);
which is super fast.这是超级快。
but if I add in a sort stage (before $limit)但如果我在排序阶段添加(在 $limit 之前)
{
$sort: {
ei0: -1
}
}
it gets REALLY slow它真的很慢
I do have a regular index on "ei0" and its included in the search index as well (defined as a Number and dynamic mapping off)我确实有一个关于“ei0”的常规索引,它也包含在搜索索引中(定义为数字和动态映射关闭)
Is there anyway to sort on any field (asc/desc), inside the search pipeline?无论如何在搜索管道内对任何字段(asc/desc)进行排序?
In the docs , they say:在文档中,他们说:
Using a $sort aggregation pipeline stage after a $search stage can drastically slow down query results.在 $search 阶段之后使用 $sort 聚合管道阶段会大大降低查询结果的速度。
You should use near operator in atlas search to sort results.您应该在图集搜索中使用near运算符来对结果进行排序。
Also you can customize your query scores to sort them.您还可以自定义查询分数以对它们进行排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.