sap - 如何在超级账本结构中索引 couchdb
问题描述
我正在尝试按我定义了索引的发布日期对结果进行排序
{
"index": {
"fields": [{
"PostingDate": "DESC"
}]
},
"ddoc": "indexPostingDate",
"name": "indexPostingDate",
"type": "json"
}
根据超级账本结构文档,我必须将它放在 META-INF/statedb/couchdb/indexes
使用 Sap hyperledger fabric 平台,我尝试将这个文件夹放在供应商文件夹中以及直接放在 src 文件夹下。但没有一个对我有用。
这是我查询结果的代码
queryString := fmt.Sprintf("{\"selector\":{\"id\":\"%s\"},\"sort\": [{\"PostingDate\": \"desc\"}],\"use_index\": \"indexPostingDate\"}",
id)
logger.Infof("Getting data for %s", id)
oResultsIterator, responseMetaData, oFetchErr := stub.GetQueryResultWithPagination(queryString,
pageSize, bookmark)
在调用此函数时,我收到以下错误
{
"error": {
"message": "GET_QUERY_RESULT failed: transaction ID: 9b7c42c09069855758ccdfbc30f5d75d38b51569a78e101584051e0fa142ebc3: error handling CouchDB request. Error:no_usable_index, Status Code:400, Reason:No index exists for this sort, try indexing by the sort fields.",
"code": "CustomError",
"status": 500
}
}
我该如何解决这个问题?
解决方案
无法在 Query with Fabric 中指定排序方向是一个已知限制。如果您需要有序搜索,您的索引创建应该指定方向,因此您可以在查询中简单地排除它。
现在我们支持并建议您使用官方的 CouchDB:3.1,这可能会起作用,但我需要对其进行测试。
顺便说一句,您可以通过使用反引号来简化查询,这样您就不必为了便于阅读和写作而转义引号:fmt.Sprintf(`{"selector":{"id":"%s"},"sort": [{"PostingDate": "desc"}],"use_index": "indexPostingDate"}`, id)
推荐阅读
- javascript - 你如何改变从同一个类中渲染的 jsx 块?
- sql - PostgreSQL 不在多个通配符中
- javascript - 我如何将 react-native 移动应用程序连接到 Django
- python - Django 服务器没有运行
- java - startActivityForResult 并在活动完成时继续
- node.js - 如何在 Google App Engine 标准环境中使用 Google Cloud Build 或其他方法设置环境变量?
- c# - 隐藏网格元素时更改 GridSplitter 行为
- java - 如何在android Studio中伪装android xml可点击链接?
- javascript - 在 Angular 应用程序上将 XML RSS 提要转换为 Json
- javascript - 如何更新文本指示器以显示进度条的进度?