在Hyperledger Composer v0.18.0到v0.19.0的查询中使用ORDER BY时出现CouchDB索引错误

在Hyperledger Composer v0.18.0到v0.19.0的查询中使用ORDER BY时出现CouchDB索引错误,couchdb,hyperledger-fabric,hyperledger,hyperledger-composer,Couchdb,Hyperledger Fabric,Hyperledger,Hyperledger Composer,在从Hyperledger Composer v0.18.0移动到v0.19.0时,我对带有ORDER BY语句的查询的CouchDB索引有问题 背景: 称为事件的简单资产: asset Event identified by id { o String id o String name o EventType eventType o DateTime scheduledTime o EventStatus status } query getSched

在从Hyperledger Composer v0.18.0移动到v0.19.0时,我对带有ORDER BY语句的查询的CouchDB索引有问题

背景:

称为事件的简单资产:

asset Event identified by id {
    o String id
    o String name
    o EventType eventType
    o DateTime scheduledTime
    o EventStatus status
}
query getScheduledEvents {
    description: "Select all the SCHEDULED Events"
    statement:
        SELECT event.network.assets.Event
            WHERE (status == 'SCHEDULED')
                ORDER BY [scheduledTime ASC]
}
带有ORDER BY语句的查询:

asset Event identified by id {
    o String id
    o String name
    o EventType eventType
    o DateTime scheduledTime
    o EventStatus status
}
query getScheduledEvents {
    description: "Select all the SCHEDULED Events"
    statement:
        SELECT event.network.assets.Event
            WHERE (status == 'SCHEDULED')
                ORDER BY [scheduledTime ASC]
}
HL合成器v0.18.0

使用Composer v0.18.0,一切正常。我可以通过REST API查询事件,只需在CouchDB上创建此索引:

{
    "type": "json",
    "def": {
    "fields": [
            {
                "scheduledTime": "asc"
            }
        ],
        "partial_filter_selector": {}
     }
}
HL合成器v0.19.0

在Composer v0.19.0(和Fabric 1.1.0)中,将在部署时自动生成索引,新索引如下所示:

{
    "type": "json",
    "def": {
        "fields": [
            {
                "\\$class": "asc"
            },
            {
                "\\$registryType": "asc"
            },
            {
                "\\$registryId": "asc"
            },
            {
                "status": "asc"
            },
            {
                "scheduledTime": "asc"
            }
        ],
        "partial_filter_selector": {}
    }
}
现在,使用Composer v0.19.0查询同一端点时,我得到以下错误:

{
"error": {
    "statusCode": 500,
    "name": "Error",
    "message": "2 UNKNOWN: error executing chaincode: transaction returned with failure: Error: Couch DB Error:no_usable_index,  Status Code:400,  Reason:No index exists for this sort, try indexing by the sort fields.",
    "code": 2,
    "metadata": {
        "_internal_repr": {}
    },
    "details": "error executing chaincode: transaction returned with failure: Error: Couch DB Error:no_usable_index,  Status Code:400,  Reason:No index exists for this sort, try indexing by the sort fields.",
"stack": "Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: Error: Couch DB Error:no_usable_index,  Status Code:400,  Reason:No index exists for this sort, try indexing by the sort fields.\n    at new createStatusError (/home/user/.nvm/versions/node/v8.11.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/client.js:64:15)\n    at /home/user/.nvm/versions/node/v8.11.1/lib/node_modules/composer-rest-server/node_modules/grpc/src/client.js:583:15"
    }
}
删除生成的索引并创建旧索引并不能解决问题,因为我仍然收到相同的错误

有什么想法吗?
谢谢大家!

我可以用一个类似的查询重新创建它,并发现我可以通过重新排列索引文档中的字段来让它工作。就你而言,安排如下:

{
    "type": "json",
    "def": {
        "fields": [
            {
                "\\$class": "asc"
            },
            {
                "\\$registryType": "asc"
            },
            {
                "\\$registryId": "asc"
            },
            {
                "scheduledTime": "asc"
            },
            {
                "status": "asc"
            }
        ],
        "partial_filter_selector": {}
    }
}

我认为这与

太好了,第3项中的解释有关!我按照您的建议重新排列了字段,现在它按预期工作。非常感谢。