Cloudant查询错误:尝试排序时缺少搜索索引
问题描述:
我已经遵循IBM的Cloudant tutorial关于如何运行查询来检索文档选择以及根据字段值对它们进行排序。这些说明在“运行带有两个字段的查询”页面的2/3处开始。Cloudant查询错误:尝试排序时缺少搜索索引
我收到一个错误,我找不到解决方案。
Unknown Error: mango_idx :: {no_usable_index,missing_sort_index}
查询是:
{
"selector": {
"lastname": "Brown",
"location": "New York City, NY"
},
"fields": [
"firstname",
"lastname",
"location"
],
"sort": [
{
"lastname": "asc"
},
{
"firstname": "asc"
}
]
}
我有一个查询索引加入到设计文件,给出:
{
"firstname": "John",
"lastname": "Brown",
"age": 21,
"location": "New York City, NY",
"_id": "doc2"
}
:
{
"index": {
"fields": [
"lastname",
"location",
"age"
]
},
"name": "query-index",
"type": "json"
}
本身的变种的文件
我做错了什么? Cloudant语法中的某些内容是否更改了教程没有更新?我知道"Unknown Error: mango_idx :: {no_usable_index,missing_sort_index}"}其中建议的答案不帮我。
答
看起来这是这个教程的问题。没有索引支持按姓氏和名字排序。您可以创建另一个指标是这样的:
{
"index": {
"fields": [
"lastname",
"firstname"
]
},
"type": "json"
}
另外,您可以排序只有姓氏(去掉姓)。这将由原始索引支持。查询应该是这样的:
{
"selector": {
"lastname": "Brown",
"location": "New York City, NY"
},
"fields": [
"firstname",
"lastname",
"location"
],
"sort": [
{
"lastname": "asc"
}
]
}
+0
非常感谢@markwatsonatx!我将使用您的解决方案更新关于该教程的github问题。 https://github.com/IBM-Bluemix-Docs/Cloudant/issues/2#issuecomment-327289797 – Joeri
的可能的复制[ “未知错误:芒果\ _idx :: {不\ _usable \ _index,缺少\ _sort \ _index}”(https://*.com/问题/ 40584988/unknown-error-mango-idx-no-useful-index-missing-sort-index) –
我已经查看了那里的建议答案,这对我没有帮助,我已经遵循了您的(IBM)教程造成这个问题的信件。我还在文档的github存储库上报告了这个问题:https://github.com/IBM-Bluemix-Docs/Cloudant/issues/2 – Joeri
@Joeri本教程将被纠正。你很快就会在这里得到正式的答复。 – ptitzler