DocumentDB:删除默认索引
DocumentDB: Removing default indexing
我正在尝试删除为新集合创建的默认索引:
{
"indexingMode": "lazy",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
},
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": []
}
据我了解,这将索引每个资源及其子资源中的每个属性。
尝试使用此排除所有内容时:
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath
{
Path = "/*"
});
client.ReplaceDocumentCollectionAsync(collection).Wait();
我在 ReplaceDocumentCollectionAsync()
上收到以下错误:
The indexing path '/*' could not be accepted. Please ensure that the
path is unique across all sets of indexing paths and it's valid.
我希望能够定义我自己的自定义索引路径。为此,我需要删除默认索引(索引所有内容)。
更新
我已通过将包含项分配给一个空集合并排除所有路径来删除索引:
collection.IndexingPolicy.IncludedPaths = new Collection<IncludedPath>();
collection.IndexingPolicy.ExcludedPaths = new Collection<ExcludedPath>();
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath
{
Path = "/*"
});
注意 1: 由于某些原因,如果只执行第一条语句,索引策略没有任何变化......并且没有错误。
注意 2: ExcludePaths
最初必须设置为空集合,否则(如果路径已经存在)它将检测到冲突并抛出错误(当然是在执行 ReplaceDocumentCollectionAsync 时)。
索引文档:
{
"indexingMode": "lazy",
"automatic": true,
"includedPaths": [
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": [
{
"path": "/*"
}
]
}
我假设 /_ts/?
路径是必需的。
听起来你已经很明白了。澄清一下,id
和 _ts
在索引方面被视为特殊属性。
id
被隐式视为文档的主键 - 其中,id
将始终以唯一性强制索引。
_ts
是上次写入文档(创建或替换)的纪元时间戳,并且也将始终被索引。这 属性 将在索引政策中明确注明。
以下索引策略说明了如何仅索引 document.prop.subprop
属性(以及 id
和 _ts
):
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/prop/subprop/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
}
]
},
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": [
{
"path": "/*"
}
]
}
排除所有内容的简单方法是切换 indexingMode:None
我正在尝试删除为新集合创建的默认索引:
{
"indexingMode": "lazy",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
},
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": []
}
据我了解,这将索引每个资源及其子资源中的每个属性。
尝试使用此排除所有内容时:
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath
{
Path = "/*"
});
client.ReplaceDocumentCollectionAsync(collection).Wait();
我在 ReplaceDocumentCollectionAsync()
上收到以下错误:
The indexing path '/*' could not be accepted. Please ensure that the path is unique across all sets of indexing paths and it's valid.
我希望能够定义我自己的自定义索引路径。为此,我需要删除默认索引(索引所有内容)。
更新
我已通过将包含项分配给一个空集合并排除所有路径来删除索引:
collection.IndexingPolicy.IncludedPaths = new Collection<IncludedPath>();
collection.IndexingPolicy.ExcludedPaths = new Collection<ExcludedPath>();
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath
{
Path = "/*"
});
注意 1: 由于某些原因,如果只执行第一条语句,索引策略没有任何变化......并且没有错误。
注意 2: ExcludePaths
最初必须设置为空集合,否则(如果路径已经存在)它将检测到冲突并抛出错误(当然是在执行 ReplaceDocumentCollectionAsync 时)。
索引文档:
{
"indexingMode": "lazy",
"automatic": true,
"includedPaths": [
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": [
{
"path": "/*"
}
]
}
我假设 /_ts/?
路径是必需的。
听起来你已经很明白了。澄清一下,id
和 _ts
在索引方面被视为特殊属性。
id
被隐式视为文档的主键 - 其中,id
将始终以唯一性强制索引。_ts
是上次写入文档(创建或替换)的纪元时间戳,并且也将始终被索引。这 属性 将在索引政策中明确注明。
以下索引策略说明了如何仅索引 document.prop.subprop
属性(以及 id
和 _ts
):
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/prop/subprop/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
}
]
},
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": [
{
"path": "/*"
}
]
}
排除所有内容的简单方法是切换 indexingMode:None