azure-cosmosdbcomposite-index

Composite index for optional field in Cosmos


I have a collection in Cosmos DB which contains documents of different types (and schemas):

{
"partKey": "...",
"type": "type1",
"data": {
    "field1": 123,
    "field2": "sdfsdf"
  }
}
{
"partKey": "...",
"type": "type2",
"data": {
    "field3": ["123", "456", "789"]
  }
}

I'm trying to create a composite index [/type, /data/field3/[]/?], but faced an issue:

The indexing path '\\/data\\/field3\\/[]\\/?' could not be accepted, failed near position '15'. Please ensure that the path is a valid path. Common errors include invalid characters or absence of quotes around labels

Solution

  • We don't support wildcards for Composite Indexes in Cosmos DB. Here is a composite index sample as reference.

    We will update our docs to be more clear in this. I looked over these and we don't currently document this today.

    Thanks.