Composite B-Tree Index

Use a composite B-tree index to combine multiple JSON scalar values into one index key.

Use this index for queries that filter on multiple fields together, especially when they filter by the leading field and optionally by additional fields. All paths must refer to the same JSON column.

Syntax

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

Create a Composite JSON SINGLEVALUE Index on Last and First Name

CREATE JSON SINGLEVALUE INDEX name_idx ON bookings b
  (b.data.traveler.last,
   b.data.traveler.first);

The index key is composed of last name and first name. Queries that filter by last name alone or by both last and first can use this index. Placing the most selective field first improves selectivity and index usefulness.

Use json_value Syntax

You can also create a composite index using json_value syntax:

CREATE INDEX name_idx ON bookings
  (json_value(data, '$.traveler.last' ERROR ON ERROR NULL ON EMPTY),
   json_value(data, '$.traveler.first' ERROR ON ERROR NULL ON EMPTY));