Multivalue JSON Function-Based Index

Use a multivalue JSON index when a path can return multiple scalar values per document.

This multivalue JSON index is most commonly used for arrays or scalar fields within an array of objects. It is typically used with json_exists predicates. Although it can index a single scalar value, a single-value JSON index or bitmap index is generally more efficient when the path returns at most one value. A multivalue JSON index is safer when schema evolution might later allow a field to repeat, even if it currently contains one value.

Syntax

CREATE JSON MULTIVALUE INDEX index_name ON table_name [table_alias]
  (dot_path [ASC | DESC], [dot_path [ASC | DESC]] ...);

Create a Multivalue JSON Index on Reservation Confirmation Numbers

CREATE JSON MULTIVALUE INDEX confirmationNo_idx ON bookings b
  (b.data.reservations.confirmationNumber.string());

The multivalue JSON index targets confirmation numbers inside an array of reservations. The string() item method fixes the indexed data type to SQL string values. Each document can contribute multiple index entries, one for each confirmation number.

Use Standard Syntax

You can also create a multivalue JSON index using standard syntax:

CREATE MULTIVALUE INDEX confirmationNo_idx ON bookings b
  (b.data.reservations[*].confirmationNumber.string());

Note: Do not include the array wildcard [*] in dot-notation multivalue JSON indexes. Use the simple path, such as b.data.reservations.confirmationNumber.string(). The [*] form is accepted in standard CREATE MULTIVALUE INDEX syntax.