Cosmos DB - Indexing Policy Settings

2019-08-27 22:47发布

问题:

I am using the azure cli in order to set my indexing policy. I am using the following JSON:

{
  "indexingMode": "consistent",
  "automatic": true,
  "includedPaths": [
    {
      "path": "/ttl/?",
      "indexes": [
        {
          "kind": "Range",
          "dataType": "Number",
          "precision": -1
        }
      ]
    }
  ],
  "excludedPaths": [
    {
      "path": "/*"
    }
  ]
}

The script reports no errors have occurred, however when I log into the portal and look at the indexing policy, it shows the following:

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/ttl/?",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "String",
                    "precision": -1
                }
            ]
        }
    ],
    "excludedPaths": [
        {
            "path": "/*"
        },
        {
            "path": "/\"_etag\"/?"
        }
    ]
}

The portal settings include an extra excludedPath and index, so I am not sure if this is intentional or I am doing something wrong. Or are the two equivalent?

Any help would be great!

回答1:

Since indexing v2 came out the default indexing will add range for both strings and numbers and it will also automatically exclude the ETag.