你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

IndexingPolicy 类

public class IndexingPolicy extends JsonSerializable

表示 Azure Cosmos DB 数据库服务中集合的索引策略配置。

构造函数摘要

构造函数 说明
IndexingPolicy()

构造函数。

IndexingPolicy(Index[] defaultIndexOverrides)

使用指定的索引集作为根路径的默认索引规范初始化 IndexingPolicy 类的新实例。

以下示例演示如何替代根路径的默认 indexingPolicy:

HashIndex hashIndexOverride = Index.Hash(DataType.String, 5);
    RangeIndex rangeIndexOverride = Index.Range(DataType.Number, 2);
    SpatialIndex spatialIndexOverride = Index.Spatial(DataType.Point);
    
    IndexingPolicy indexingPolicy = new IndexingPolicy(hashIndexOverride, rangeIndexOverride, spatialIndexOverride);
    

如果只想替代 Numbers 的 indexingPolicy,可以仅指定以下内容:

RangeIndex rangeIndexOverride = Index.Range(DataType.Number, 2);
    
    IndexingPolicy indexingPolicy = new IndexingPolicy(rangeIndexOverride);
    

IndexingPolicy(String jsonString)

构造函数。

方法摘要

修饰符和类型 方法和描述
Boolean getAutomatic()

获取是否为集合启用自动索引。

在自动索引中,可以使用 RequestOptions 从索引中显式排除文档。 在手动索引中,可以显式包含文档。

Collection<ArrayList<CompositePath>> getCompositeIndexes()

获取其他索引的复合索引。

Collection<ExcludedPath> getExcludedPaths()

获取未编制索引的路径。

Collection<IncludedPath> getIncludedPaths()

获取用户选择要编制索引的路径。

IndexingMode getIndexingMode()

获取 (一致或延迟) 的索引模式。

Collection<SpatialSpec> getSpatialIndexes()

设置其他索引的空间索引。

void setAutomatic(boolean automatic)

设置是否为集合启用自动索引。

在自动索引中,可以使用 RequestOptions 从索引中显式排除文档。 在手动索引中,可以显式包含文档。

void setCompositeIndexes(Collection<ArrayList<CompositePath>> compositeIndexes)

设置其他索引的复合索引。

void setExcludedPaths(Collection<ExcludedPath> excludedPaths)
void setIncludedPaths(Collection<IncludedPath> includedPaths)
void setIndexingMode(IndexingMode indexingMode)

设置索引模式 (一致或延迟) 。

void setSpatialIndexes(Collection<SpatialSpec> spatialIndexes)

设置其他索引的空间索引。

继承成员

构造函数详细信息

IndexingPolicy

public IndexingPolicy()

构造函数。

IndexingPolicy

public IndexingPolicy(Index[] defaultIndexOverrides)

使用指定的索引集作为根路径的默认索引规范初始化 IndexingPolicy 类的新实例。

以下示例演示如何替代根路径的默认 indexingPolicy:

HashIndex hashIndexOverride = Index.Hash(DataType.String, 5);
    RangeIndex rangeIndexOverride = Index.Range(DataType.Number, 2);
    SpatialIndex spatialIndexOverride = Index.Spatial(DataType.Point);
    
    IndexingPolicy indexingPolicy = new IndexingPolicy(hashIndexOverride, rangeIndexOverride, spatialIndexOverride);
    

如果只想替代 Numbers 的 indexingPolicy,可以仅指定以下内容:

RangeIndex rangeIndexOverride = Index.Range(DataType.Number, 2);
    
    IndexingPolicy indexingPolicy = new IndexingPolicy(rangeIndexOverride);
    

参数:

defaultIndexOverrides - 逗号分隔的索引集,用作根路径的默认索引规范。

IndexingPolicy

public IndexingPolicy(String jsonString)

构造函数。

参数:

jsonString - 表示索引策略的 json 字符串。

方法详细信息

getAutomatic

public Boolean getAutomatic()

获取是否为集合启用自动索引。

在自动索引中,可以使用 RequestOptions 从索引中显式排除文档。 在手动索引中,可以显式包含文档。

返回:

自动

getCompositeIndexes

public Collection> getCompositeIndexes()

获取其他索引的复合索引。

返回:

组合索引。

getExcludedPaths

public Collection getExcludedPaths()

获取未编制索引的路径。

返回:

排除的路径。

getIncludedPaths

public Collection getIncludedPaths()

获取用户选择要编制索引的路径。

返回:

包含的路径。

getIndexingMode

public IndexingMode getIndexingMode()

获取 (一致或延迟) 的索引模式。

返回:

索引模式。

getSpatialIndexes

public Collection getSpatialIndexes()

设置其他索引的空间索引。

返回:

空间索引。

setAutomatic

public void setAutomatic(boolean automatic)

设置是否为集合启用自动索引。

在自动索引中,可以使用 RequestOptions 从索引中显式排除文档。 在手动索引中,可以显式包含文档。

参数:

automatic - 自动

setCompositeIndexes

public void setCompositeIndexes(Collection> compositeIndexes)

设置其他索引的复合索引。

参数:

compositeIndexes - 组合索引。

setExcludedPaths

public void setExcludedPaths(Collection excludedPaths)

参数:

excludedPaths

setIncludedPaths

public void setIncludedPaths(Collection includedPaths)

参数:

includedPaths

setIndexingMode

public void setIndexingMode(IndexingMode indexingMode)

设置索引模式 (一致或延迟) 。

参数:

indexingMode - 索引模式。

setSpatialIndexes

public void setSpatialIndexes(Collection spatialIndexes)

设置其他索引的空间索引。

参数:

spatialIndexes - 空间索引。

适用于