composite

A composite term over the elements at path, keying fields together.

The kind to reach for when a conjunction over an array must hold within one element:

IndexDefinition.composite("$.items[*]", "$.sku", "$.qty")
// answers: elemMatch("$.items[*]", and(path("$.sku") eq "A", path("$.qty") eq 5))

Without it that question is asked as an uncorrelated conjunction, which is a superset: measured over corpora whose element fields vary independently, it returns 5-6x the documents a caller keeps, and the rate rises with the elements per document. Over a corpus whose fields move together it returns exactly the right ones, and this index earns nothing — which is why it is asked for rather than recommended.

fields are relative to one element and must be single-valued within it: field steps only, no wildcard. See CompositeTerm.

Throws

if fields is empty, names a path twice, or holds a wildcard.


fun composite(expression: String, vararg fields: String): IndexDefinition

The same, from expressions: composite("$.items[*]", "$.sku", "$.qty").