CREATE INDEX ix1 ON default( ALL ARRAY v.type FOR v IN OBJECT_VALUES(devices) END);
SELECT * FROM default d WHERE ANY v IN OBJECT_VALUES(d.devices) SATISFIES v.type = "light" END;
SELECT v FROM default d
UNNEST OBJECT_VALUES(d.devices) AS v
WHERE v.type = "light";
Does the index help this query at all ? the explain and plan is telling me this: (in/out)
NOTE: I did search for a key that does not exist at all and it fetch 5 document
index scan */29
If you searched that doesn’t exist it should have returned 0/0 in indexscan if the index suggested earlier used.
I am not sure what index is used. If it is primary that means you might not have that many objects that has devices.
May be leading keys are filtering more and reducing. If the data is like that even you can try this index
CREATE INDEX my_index ON data ((split((meta(). id ), “::”)),(split((meta(). id ), “::”)),(split((meta(). id ), “::”))); – makes index smaller
See what in/out and timing.
Post the query will able to help any other suggestions
I guess I know what happened , I had index on 5 data point, and the type was the fifth one, but in query I forgot to add 4th datapoint in where , so the 5th index was excluded from the index execution plan