1

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
José Pedro
  • 1,097
  • 3
  • 14
  • 24
dr11
  • 5,166
  • 11
  • 35
  • 77

2 Answers2

2

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.

Mark Brown
  • 8,113
  • 2
  • 17
  • 21
  • not sure I understand this. what exactly is a wildcard in my example? https://learn.microsoft.com/en-us/azure/cosmos-db/index-policy - an example for locations array – dr11 Apr 27 '20 at 18:26
  • 1
    The ? in your index policy. Please see our docs on composite indexes for details on how to define these. Thanks – Mark Brown Apr 27 '20 at 19:55
0

In composite indexes, you just need to specify the paths that you want to index, rather than the values, so for your example:

"compositeIndexes":[  
        [  
            {  
                "path":"/type",
                "order":"ascending"
            },
            {  
                "path":"/data/field3",
                "order":"descending"
            }
        ]
    ]

Just specify the order type you need for your queries (I've just used these ones as an example).

For different documents that have different properties underneath your data property, I believe you will have to add each composite index for each use case that you need since composite indexes don't support wildcards, so you would need to add:

/data/field1 /data/field2 etc etc

Hope this helps.

Will V
  • 390
  • 2
  • 13