该沙发床索引有什么问题?

时间:2019-03-07 21:51:32

标签: couchbase n1ql

我创建了这个沙发索引

CREATE INDEX `idx_additionalOrderCode` ON 
`order`(ALL ARRAY s.`value` FOR s IN additionalOrderCode WHEN s.`typeCode`= "MYCODE" END)
WHERE _class = "com.entrprise.OrderEntity" 

基于此页面中的示例

https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/indexing-arrays.html

但是当我使用这个选择查询来查询该索引时:

SELECT * FROM `order` 
WHERE `_class` = "com.entrprise.OrderEntity" 
AND ANY s IN additionalOrderCode SATISFIES ( s.`value` = "130047777" ) and (s.typeCode = "MYCODE" ) END

我收到错误

 "msg": "No index available on keyspace order that matches your query. Use CREATE INDEX or CREATE PRIMARY INDEX to create an index, or check that your expected index is online."

没有主索引支持查询,我希望所有查询都由辅助索引支持。

我正在使用Enterprise Edition 6.0.0 build 1693

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

使用该索引解决了它(我只删除了distinct和array之间的所有内容)

CREATE INDEX `idx_additionalOrderCode` ON `order`
 (distinct (array (aoc.`value`) for `aoc` in `additionalOrderCode` WHEN aoc.`typeCode`= "WLEC"  END), orderTypeCode)
 WHERE (`_class` = "com.entreprise.OrderEntity")