“未知错误:mango_idx :: {no_usable_index,missing_sort_index}”}

2023-12-09

我有以下查询:

{'type': 'text', 
 'name': 'album-rating-text', 
 'index': {'fields': [
                      {'type': 'string', 'name': 'user_id'}, 
                      {'type': 'string', 'name': 'album_id'}, 
                      {'type': 'number', 'name': 'timestamp'}
]}}

这是查询:

{'sort': [
           {'user_id': 'desc'}, 
           {'album_id': 'desc'}, 
           {'timestamp': 'desc'}
         ], 
 'limit': 1, 
 'fields': ['user_id', 'album_id', 'timestamp'], 
 'selector': {
              '$and': [
                        {'user_id': {'$eq': '[email protected]'}},         
                        {'album_id': {'$in': ['bf129f0d', '380e3a05'
                      ]
}}]}}

错误:

{ 
 "error":"unknown_error",
 "reason":"Unknown Error: mango_idx :: {no_usable_index,missing_sort_index}"
}

我见过一个类似的问题但是,我索引的所有字段都在我的排序列表中。


Update:

作为解决方法,我尝试通过删除时间戳字段来简化:

{"type": "text", 
 "name": "album-rating-text", 
 "index": {"fields": [
               {"type": "string", "name": "user_id"}, 
               {"type": "string", "name": "album_id"}
 ]}}

并这样查询...

{"selector": {"$and": [
                   {"user_id": {"$eq": "[email protected]"}}, 
                   {"album_id": {"$in": ["bf129f0d", "380e3a05"]}
              }]}, 
 "fields": ["user_id", "album_id"]}

我收到以下错误:

 {"warning":"no matching index found, create an index to optimize query time",
"docs":[
]}

要对自定义字段使用排序功能,该字段需要manually注册到“查询索引”。

Cloudant 不会这样做,因为它会消耗资源:

“编辑器中的示例显示了如何使用索引字段“foo” json 类型索引。您可以自动索引所有字段中的所有字段 使用文本类型索引和语法 '{ "index": {}, "type": "text" }', 注意索引所有字段都可以是资源 消耗大数据集。”

您可以使用 Cloudant 仪表板来执行此操作。转到您的数据库并查找“可查询索引”。单击编辑。

将您的字段添加到默认模板:

{
  "index": {
    "fields": [
      "user_id"
    ]
  },
  "type": "json"
}

按“创建索引”

字段“user_id”现在可以查询,并且您现在可以对其使用排序功能。 所有字段都需要手动添加,或者您可以将所有字段注册为查询索引: {“索引”:{},“类型”:“文本”}

创建查询索引的视频说明:https://www.youtube.com/watch?v=B3ZkxSFau8U

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“未知错误:mango_idx :: {no_usable_index,missing_sort_index}”} 的相关文章

随机推荐