我有一个带有ORDER BY子句的命名查询:
`query OrdersByRequesterSort {
description: "Select all orders by requester"
statement:
SELECT org.test.sample.Order
WHERE (requester == _$requesterParam)
ORDER BY [placeTimestamp DESC]
}`
我在看到的查询之后拍了一下:
https://hyperledger.github.io/composer/reference/query-language.html
当我尝试执行此查询时,我收到以下错误:
`
{
"error": {
"statusCode": 500,
"name": "Error",
"message": "Error trying to query chaincode. Error: chaincode error (status: 500, message: Error: http: read on closed response body)",
"stack": "Error: Error trying to query chaincode. Error: chaincode error (status: 500, message: Error: http: read on closed response body)\n at channel.queryByChaincode.then.catch (/Users/bower/.nvm/versions/node/v6.3.0/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:779:34)"
}
}`
我做错了吗?这支持了吗?
提前致谢。
答案 0 :(得分:1)
对于我的网络,我按时间戳命令从HistorianRecord返回查询:
query getAllHistorianRecords {
description: "getTradeRelatedHistorianRecords"
statement:
SELECT org.hyperledger.composer.system.HistorianRecord
WHERE (transactionTimestamp > '0000-01-01T00:00:00.000Z')
ORDER BY [transactionTimestamp ASC]
}
要使这个ORDER BY
语句工作,我必须在CouchDB中创建一个索引。如果您使用脚本创建结构,则数据库应位于http://localhost:5984/_utils/#database/composerchannel/_all_docs
。
curl -X POST --header 'Content-Type: application/json' --header
'Accept: application/json' -d '
{
"index": {
"fields": [
{
"data.transactionTimestamp": "asc"
}
]
},
"type": "json"
}' 'http://localhost:5984/composerchannel/_index'
此curl将创建一个索引,查询可用于启用ORDER BY
答案 1 :(得分:0)
看起来您需要在CouchDB中为数据类型定义排序索引以使用ORDER BY
。