我已經看過這個問題很多次了,但在這里我問的是同樣的問題。
為什么我會收到此錯誤:
Error running query. Reason: (no_usable_index) No index exists for this sort try indexing by the sort fields.
我正在運行一個帶有超級賬本結構的區塊鏈服務,并且我正在使用 CouchDB for the World State。在這些資料中,我有一個日期欄位,我想按日期對資料進行排序。這是我的芒果查詢:
{
"selector": {
"date": {
"$gte": null
},
"_id": {
"$gte": null
}
},
"fields": [
"_id",
"date"
],
"sort": [
{
"date": "asc"
}
]
}
值得一提的是,日期是一個字串。我不知道這里發生了什么,因為我嘗試了一切。我嘗試使用表格的任何欄位進行排序,但唯一要排序和作業的是該欄位:_id
我什至嘗試了_rev再次_id出現錯誤的欄位。
{
"selector": {
"_rev": {
"$gte": null
},
"_id": {
"$gte": null
}
},
"fields": [
"_id",
"_rev"
],
"sort": [
{
"_id": "asc"
},
{
"_rev": "asc"
}
]
}
這是我的資料示例:
{
"id": "438c5ad0868db83201bdc36edb7705e3081c73821b20d14d4c4251af3e49c04e",
"key": "438c5ad0868db83201bdc36edb7705e3081c73821b20d14d4c4251af3e49c04e",
"value": {
"rev": "1-4f2cc5b932d393a88b3497a3942fff33"
},
"doc": {
"_id": "438c5ad0868db83201bdc36edb7705e3081c73821b20d14d4c4251af3e49c04e",
"_rev": "1-4f2cc5b932d393a88b3497a3942fff33",
"company": "greenTea",
"date": "2022-02-04 15:40:23.337 0000 UTC",
"fromacc": "Gary",
"operation": "",
"txid": "438c5ad0868db83201bdc36edb7705e3081c73821b20d14d4c4251af3e49c04e",
"type": "transaction",
"~version": "CgMBBwA="
}
}
我已經嘗試了我在網上找到的任何東西,但我無法讓它作業。任何幫助或建議,甚至是好的檔案都將不勝感激。
謝謝
uj5u.com熱心網友回復:
除了收集結果所需的全表掃描之外,想象一下如果有 100 億個檔案要在記憶體中排序會發生什么。
date如果要對欄位進行排序,則需要創建索引。
只需添加這樣的索引。
{
"index": {
"fields": [
"date"
]
},
"name": "date-index"
}
你會發現這個查詢成功了:
{
"selector": {
"date": {
"$gte": null
},
"_id": {
"$gte": null
}
},
"fields": [
"_id",
"date"
]
}
這個查詢可能有一些效率
{
"selector": {
"date": {
"$gte": 9
},
"_id": {
"$gte": 9
}
},
"fields": [
"_id",
"date"
]
}
由于兩個欄位都是字串型別,請參見3.2.2.5。整理規范
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/427536.html
標籤:排序 沙发数据库 couchdb-芒果
