What would be the best way to index the values within translations dynamically? I.e. a generic index that indexes all keys within the translations object.
CREATE INDEX ix1 ON bucket(DISTINCT ARRAY [v.name, v.val ] FOR v IN OBJECT_PAIRS(translations) END)
WHERE type = "article";
SELECT *
FROM bucket
WHERE type = "article"
AND ANY v IN OBJECT_PAIRS(translations) SATISFIES [v.name,v.val] = ["en", "Hello"] END
For non equality predicate index either name or val then other apply post indexscan
CREATE INDEX ix2 ON bucket(DISTINCT ARRAY v.name FOR v IN OBJECT_PAIRS(translations) END)
WHERE type = "article";
SELECT *
FROM bucket
WHERE type = "article"
AND ANY v IN OBJECT_PAIRS(translations) SATISFIES v.name = "en" AND v.val LIKE "Hell%" END
In this values not objects or arrays, are more distinct following might perform better because indexScan produce less items
CREATE INDEX ix2 ON bucket(DISTINCT OBJECT_VALUES(translations) )
WHERE type = "article";
SELECT *
FROM bucket
WHERE type = "article"
AND translations.en LIKE "Hell%" ANY v IN OBJECT_VALUES(translations) SATISFIES v LIKE "Hell%" END;
OR
SELECT *
FROM bucket
WHERE type = "article"
AND translations.["en"] LIKE "Hell%"
AND ANY v IN OBJECT_VALUES(translations) SATISFIES v LIKE "Hell%" END;
CREATE INDEX ix1 ON bucket (
DISTINCT [v.name, v.val ]
FOR v IN OBJECT_PAIRS(translations) END
) WHERE type = "article";
Gives the following error upon creation:
[
{
"code": 3000,
"msg": "syntax error - at FOR",
"query_from_user": "CREATE INDEX ix1 ON bucket (DISTINCT [v.name, v.val ] FOR v IN OBJECT_PAIRS(translations) END)\n WHERE type = \"article\";"
}
]
What’d be the correct syntax here? Much appreciated!