如何在 couchbase 的对象中添加索引和查询数组?

How to add index and query array within object in couchbase?

有多个文档的结构与此类似:

{
'key1':value,
'key2':value2,
'galaxy':{
           'planets':['earth','mars','welcomebackpluto']
           'sun': 'something'
          }
}

我想查询 galaxy 对象中 planets 数组中包含 mars 的所有文档。

我创建的索引没有用,我无法查询它们,知道怎么做吗?

使用数组索引

CREATE INDEX ix1 ON default (DISTINCT ARRAY (DISTINCT ARRAY p FOR p IN g.planets END) FOR g IN galaxy END) WHERE type = "xyz";

SELECT d.*
FROM default AS d
WHERE d.type = "xyz" AND ANY g IN d.galaxy SATISFIES (ANY p IN g.planets SATISFIES p = "mars" END) END;

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