I have the following below. I want to find matches on multiple attributes but can not get it working. Anyone have an idea? Edited: I replaced ‘key’ with k and ‘value’ with v.
Index:
CREATE INDEX entity_attributes_key_value_idx ON couchbase_test(DISTINCT ARRAY (attribute.k || attribute.v) FOR attribute IN attributes END) WHERE _class = "BaseEntity" USING GSI;
Document:
{ "updateTime": 1462028351012, "location": { "x": -78, "y": 33 }, "attributes": [ { "classification": "U", "v": "0", "k": "0" }, { "classification": "U", "v": "0", "k": "1" }, { "classification": "U", "v": "0", "k": "2" }, { "classification": "U", "v": "0", "k": "3" }, { "classification": "U", "v": "0", "k": "4" }, { "classification": "U", "v": "0", "k": "5" }, { "classification": "U", "v": "0", "k": "6" }, { "classification": "U", "v": "0", "k": "7" }, { "classification": "U", "v": "0", "k": "8" }, { "classification": "U", "v": "0", "k": "9" } ], "_class": "BaseEntity" }
Query 1:
SELECT couchbase_test.* FROM couchbase_test WHERE _class = "BaseEntity" AND ANY attribute IN attributes SATISFIES (attribute.k || attribute.v) = ("0" || "0") END AND ANY attribute IN attributes SATISFIES (attribute.k || attribute.v) = ("1" || "0") END
== no match…cannot match both at same time
Query 2:
SELECT couchbase_test.* FROM couchbase_test WHERE _class = "BaseEntity" AND ANY attribute1 IN attributes, ANY attribute2 IN attributes SATISFIES (attribute1.k || attribute1.v) = ("0" || "0") AND (attribute2.k || attribute2.v) = ("1" || "0") END
== no index found…does not match index text
Query 3:
SELECT couchbase_test.* FROM couchbase_test WHERE _class = "BaseEntity" AND ANY attribute1 IN attributes SATISFIES (attribute1.k || attribute1.v) = ("0" || "0") END AND ANY attribute2 IN attributes SATISFIES (attribute2.k || attribute2.v) = ("1" || "0") END
== no index found…does not match index text
Query 4:
SELECT couchbase_test.* FROM couchbase_test UNNEST couchbase_test.attributes attribute WHERE _class = "BaseEntity" AND EXISTS (SELECT attribute.k WHERE (attribute.k || attribute.v) = ("0" || "0")) AND EXISTS (SELECT attribute.k WHERE (attribute.k || attribute.v) = ("1" || "0"))
== no index found…not sure