2
votes

I have following document structure in cosmos db:

{
 "insertDate": "10-10-2016",
 "docName" : "dname",
 "subDoc": {
     "aggregate": {
             "first": 1,
             "second": 2
      }
     "result": [
         {
          "name": "key",
          "count": 1
         },
         {
          "name": "val"
          "count": 2
         }
     ]
}
}

While creating a collection in cosmosdb, I need to define index on subDoc/aggregate (not it's sub-elements) and subDoc/result array.

Can someone check if my indexing is correct ?

For subDoc/aggreate, I have it like this:

 {
     "path": "/\"subDoc/aggreate\"/?",
     "indexes": [
         {
             "kind": "Hash",
             "dataType": "String",
             "precision": 3
         },
         {
             "kind": "Range",
              "dataType": "Number",
              "precision": -1
         }
     ]
}

For array part, the index looks like this:

{
            "path": "/\subDoc/result/[]\"/?",
            "indexes": [
                {
                    "kind": "Hash",
                    "dataType": "String",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                }
            ]
        }
1

1 Answers

0
votes

You need to replace '?' by '*':

"path": "/subDoc/aggregate/*"

Also, it's recommended to opt for Range index w/ precision of -1 for both Number and String data types (even if all values are expected to be numbers).

To index everything under result array:

"path": "/subDoc/result/*"