I’m trying to write an index for the below sql query. i’ve tried creating an index but it seems that the index is not being picked up by the query. any help would be appreciated. TIA
SELECT d.*, meta(d).id FROM cmw as d WHERE meta(d).id like ‘wat%’ and ANY v IN OBJECT_VALUES(d.watches.series) SATISFIES v.external_id = “6a71f42432484025a6c1e43fb44b6df8” END;
– example but doesn’t work for the sql query
CREATE INDEX cmw_external_id1 ON cmw( DISTINCT ARRAY [d.watches.series] FOR v IN OBJECT_VALUES(v.external_id) END);
CREATE INDEX ix1 ON cmw( DISTINCT ARRAY v.external_id FOR v IN OBJECT_VALUES(watches.series) END)
WHERE META().id LIKE "wat%";
SELECT d.*, META(d).id
FROM cmw AS d
WHERE META(d).id LIKE "wat%"
AND ANY v IN OBJECT_VALUES(d.watches.series) SATISFIES v.external_id = "6a71f42432484025a6c1e43fb44b6df8" END;
OR
CREATE INDEX ix2 ON cmw( DISTINCT ARRAY v.external_id FOR n:v IN watches.series END)
WHERE META().id LIKE "wat%";
SELECT d.*, META(d).id
FROM cmw AS d
WHERE META(d).id LIKE "wat%"
AND ANY n:v IN d.watches.series SATISFIES v.external_id = "6a71f42432484025a6c1e43fb44b6df8" END;
If you want use directly object
FOR n:v IN d.watches.series END
iterates each field of d.watches.series (n holds name, v holds value)