单个 属性 的 documentdb 索引

documentdb indexing for a single property

我正在尝试仅对 ExpireDate 属性 进行范围索引。我写了以下索引。这是正确的吗?

如果我设置automatic = false,我将无法查询。但是,我担心的是因为 automatic = true,所有级别的所有属性都被索引,这是我不想要的。

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

如果 ExpireDate 是一个数字,那么这是正确的。如果它表示为字符串,例如ISO-8601,您希望将索引设置为字符串和数字的范围,即像下面的存根一样。注意这是配置

    {
      "path": "/ExpireDate/?",
      "indexes": [
        {
          "kind": "Range",
          "dataType": "Number",
          "precision": -1
        },
        {
          "kind": "Range",
          "dataType": "String",
          "precision": -1
        }
      ]
}

大多数情况下应将自动设置为真。它指示 documents 是否应该默认选择加入索引。如果这是错误的,您需要在文档写入时明确传递 IndexingDirective.Include。如果设置为 true,则需要传入 IndexingDirective.Exclude 以明确排除文档。无论自动 true/false,只有上述规则涵盖的路径(默认所有内容,在本例中为 ExpireDate)将被索引。