Database Cloudant:此排序不存在索引,请尝试按排序字段编制索引
我有一个问题持续了几天,我无法解决它 我的数据库中有一个简单的文档,如下所示:Database Cloudant:此排序不存在索引,请尝试按排序字段编制索引,database,sorting,nosql,couchdb,cloudant,Database,Sorting,Nosql,Couchdb,Cloudant,我有一个问题持续了几天,我无法解决它 我的数据库中有一个简单的文档,如下所示: { "_id": "asd123", "_rev": "revidasd123", "type": "CUSTOM_TYPE", "position": 8, "title": "Short custom title" } 当我尝试按位置进行排序时,即使我已为此字段创建了索引,也总是会出现相同的错误: 错误:没有可用的索引。原因:此排序不存在索引,请尝试按排序字段编制索引 以下是索引: { "
{
"_id": "asd123",
"_rev": "revidasd123",
"type": "CUSTOM_TYPE",
"position": 8,
"title": "Short custom title"
}
当我尝试按位置进行排序时,即使我已为此字段创建了索引,也总是会出现相同的错误:
错误:没有可用的索引。原因:此排序不存在索引,请尝试按排序字段编制索引
以下是索引:
{
"type": "json",
"def": {
"fields": [
{
"position": "asc"
}
]
}
}
以下是导致此错误的查询:
{
"selector": {
"type": "CUSTOM_TYPE",
"_id":{
"$gt": null
}
},
"fields": [
"_id",
"type",
"position"
],
"sort": [
{
"_id": "asc"
},
{
"position": "asc"
}
]
}
结果:此排序不存在索引,请尝试按排序字段编制索引。
请帮忙提前感谢如果要按职位排序,请尝试以下查询:
{
"selector": {
"type": "CUSTOM_TYPE",
"position": {"$gte": 0}
},
"fields": [
"_id",
"type",
"position"
],
"sort": [
{
"position": "asc"
}
]
}
位置
字段需要是选择器的一部分。我将它设置为匹配>=0的任何位置,因此它应该匹配所有位置,除非它为null
此外,您还按
\u id
排序,然后按位置进行排序。这将使位置
排序变得毫无意义。我从排序中删除了\u id
字段。非常感谢,@markwatsonatx。这解决了我的问题。我也在选择器中包含了位置,但我没有删除_id,所以可能这也给我带来了一个错误。。