Hyperledger Fabric CouchDB索引:“;未找到匹配的索引";
我在Hyperledger Fabric CouchDB索引:“;未找到匹配的索引";,couchdb,hyperledger-fabric,Couchdb,Hyperledger Fabric,我在META-INF\statedb\couchdb\index目录中的链码旁边创建了一个索引。索引的json如下所示: { "index": { "fields": ["id", "docType", "type"] }, "ddoc" : "indexTestDoc", "name" : "indexTest", "type" : "json" } 通过查看日志,我可以确认索引在创建和更新过程中是否正确: Created Couch
META-INF\statedb\couchdb\index
目录中的链码旁边创建了一个索引。索引的json如下所示:
{
"index": {
"fields": ["id", "docType", "type"]
},
"ddoc" : "indexTestDoc",
"name" : "indexTest",
"type" : "json"
}
通过查看日志,我可以确认索引在创建和更新过程中是否正确:
Created CouchDB index [indexTest] in state database [integrity-channel_approvalcc] using design document [_design/indexTestDoc]\n","stream":"stderr","time":"2019-08-15T10:48:01.42015813Z"}
问题是查询不使用索引,尽管我在查询字符串中指定了use\u index
属性:
"{\"selector\":{\"docType\":\"foo\", \"type\":\"bar\"}, \"use_index\":[\"_design/indexTestDoc\", \"indexTest\"]}"
我将id
作为索引中的附加字段是否有问题?您的索引位于[“id”、“docType”、“type”]
,但您没有查询id
,因此它无法使用该索引
或者从索引中删除id
(建议这样做,因为几乎没有任何理由明确索引id
):
或者将其添加到查询中:
{
"selector": {
"docType": "foo",
"type": "bar",
"id": "baz"
},
"use_index": [
"_design/indexTestDoc",
"indexTest"
]
}
如果您确实需要在所有三个字段上建立索引,但只想查询两个字段,请确保您查询的两个字段是第一个字段。即,将id
放在最后:
{
"index": {
"fields": ["docType", "type", "id"]
},
"ddoc" : "indexTestDoc",
"name" : "indexTest",
"type" : "json"
}
如上所述,几乎没有理由在id
上创建手动索引,因为它已经是唯一的,并且已经有了内置索引。我想不出有哪种情况下您会想要在id上创建索引,所以只需从索引中删除它即可。但是其他解决方案仍然适用于其他索引。因此JSON是{“选择器”:{“docType”:“foo”,“type”:“bar”},“use_index”:“indexTestDoc”}
-根据需要使用反斜杠等
{
"index": {
"fields": ["docType", "type", "id"]
},
"ddoc" : "indexTestDoc",
"name" : "indexTest",
"type" : "json"
}