Hello,
I have a bucket with documents like this:
{
"fd": [{
"ac": "AF",
"d": 30,
"fn": 1096,
"ym": 1911
}, {
"ac": "AF",
"d": 9,
"fn": 1053,
"ym": 2009
}, {
"ac": "BA",
"d": 29,
"fn": 1002,
"ym": 2006
}, {
"ac": "QR",
"d": 6,
"fn": 1764,
"ym": 2011
}
],
"ts": 1572258925.187879,
"yld": [
"PEKAMS",
"CDGORY"
]
}
I am trying to index, as a composite index the following fields: fd.ac, fd.ym, fd.d, i.e. I need to be able to perform query only targeting the first 1 or 2 fields.
I’ve create an index like this:
CREATE INDEX idx1 ON bucket (DISTINCT ARRAY [f.ac, f.ym, f.d] FOR f IN fd END)
But Couchbase is not able to use it as a composite index, only as a “normal” index, e.g. each element in the array pushes only 1 key in the index.
For instance this query will not work:
SELECT RAW meta().id FROM bucket WHERE ANY f IN fd SATISFIES (f.ac == ‘AF’) END
Couchbase will tell me that no index is suitable for this query (even if I explicitly add a USE INDEX).
Only queries like this, specifying all the fields work:
SELECT RAW meta().id FROM bucket WHERE ANY f IN fd SATISFIES [f.ac, f.ym, f.d] == [“AF”, 1911, 30] END
Going through the documentation I’m not able to find a case like that. Is there a way to do this in Couchbase? Currently I’m using version 5.5.
Thanks a lot for your help!