Cloudant:此排序不存在索引,请尝试按排序字段建立索引 [英] Cloudant: No index exists for this sort, try indexing by the sort fields
问题描述
我的问题持续了几天,我无法解决.
I have a problem that persists for a few days and I cannot solve it.
我的数据库中有一个简单的文档,如下所示:
I have a simple document in my database which looks like this:
{
"_id": "asd123",
"_rev": "revidasd123",
"type": "CUSTOM_TYPE",
"position": 8,
"title": "Short custom title"
}
当我尝试按位置进行排序时,即使我为此字段创建了索引,也总是会遇到相同的错误:
When I try to make a sort by position, even if I have created an index for this field, I always get the same error:
错误:no_usable_index.原因:这种排序不存在索引,请尝试按排序字段建立索引.
这里是索引:
{
"type": "json",
"def": {
"fields": [
{
"position": "asc"
}
]
}
}
这是导致此错误的我的查询:
And here is my query which cause this error:
{
"selector": {
"type": "CUSTOM_TYPE",
"_id":{
"$gt": null
}
},
"fields": [
"_id",
"type",
"position"
],
"sort": [
{
"_id": "asc"
},
{
"position": "asc"
}
]
}
结果:该排序没有索引,请尝试按排序字段建立索引.
请帮助!在此先感谢
推荐答案
如果要按位置排序,请尝试以下查询:
If you want to sort by position then try this query:
{
"selector": {
"type": "CUSTOM_TYPE",
"position": {"$gte": 0}
},
"fields": [
"_id",
"type",
"position"
],
"sort": [
{
"position": "asc"
}
]
}
position
字段必须是选择器的一部分.我将其设置为匹配> = 0的任何位置,因此除非它为null,否则应该匹配所有位置.
The position
field needs to be part of the selector. I set it to match any position that is >= 0, so it should match all unless it's null.
此外,您还按_id
和position
进行排序.这将使position
排序变得毫无意义.我从排序中删除了_id
字段.
Also, you were sorting by _id
and then position
. This would render the position
sort meaningless. I removed the _id
field from the sort.
这篇关于Cloudant:此排序不存在索引,请尝试按排序字段建立索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!