Index Class

public class Index extends JsonSerializable

Represents the index of a collection in the Azure Cosmos DB database service.

Constructor Summary

Constructor Description
Index(IndexKind indexKind)

Constructor.

Index(String jsonString, IndexKind indexKind)

Constructor.

Method Summary

Modifier and Type Method and Description
IndexKind getKind()

Gets index kind.

HashIndex Hash(DataType dataType)

Returns an instance of HashIndex class with specified DataType.

Here is an example to create HashIndex instance passing in the DataType:

HashIndex hashIndex = Index.Hash(DataType.String);
</code></pre></p>

HashIndex Hash(DataType dataType, int precision)

Returns an instance of HashIndex class with specified DataType and precision.

Here is an example to create HashIndex instance passing in the DataType and precision:

HashIndex hashIndex = Index.Hash(DataType.String, 3);

RangeIndex Range(DataType dataType)

Returns an instance of RangeIndex class with specified DataType.

Here is an example to create RangeIndex instance passing in the DataType:

RangeIndex rangeIndex = Index.Range(DataType.Number);
</code></pre></p>

RangeIndex Range(DataType dataType, int precision)

Returns an instance of RangeIndex class with specified DataType and precision.

Here is an example to create RangeIndex instance passing in the DataType and precision:

RangeIndex rangeIndex = Index.Range(DataType.Number, -1);
</code></pre></p>

SpatialIndex Spatial(DataType dataType)

Returns an instance of SpatialIndex class with specified DataType.

Here is an example to create SpatialIndex instance passing in the DataType:

SpatialIndex spatialIndex = Index.Spatial(DataType.Point);

Inherited Members

Constructor Details

Index

protected Index(IndexKind indexKind)

Constructor.

Parameters:

indexKind - the kind of the index

Index

protected Index(String jsonString, IndexKind indexKind)

Constructor.

Parameters:

jsonString - the json string that represents the index.
indexKind - the kind of the index

Method Details

getKind

public IndexKind getKind()

Gets index kind.

Returns:

the index kind.

Hash

public static HashIndex Hash(DataType dataType)

Returns an instance of HashIndex class with specified DataType.

Here is an example to create HashIndex instance passing in the DataType:

HashIndex hashIndex = Index.Hash(DataType.String);
</code></pre></p>

Parameters:

dataType - specifies the target data type for the index path specification.

Returns:

an instance of HashIndex type.

Hash

public static HashIndex Hash(DataType dataType, int precision)

Returns an instance of HashIndex class with specified DataType and precision.

Here is an example to create HashIndex instance passing in the DataType and precision:

HashIndex hashIndex = Index.Hash(DataType.String, 3);

Parameters:

dataType - specifies the target data type for the index path specification.
precision - specifies the precision to be used for the data type associated with this index.

Returns:

an instance of HashIndex type.

Range

public static RangeIndex Range(DataType dataType)

Returns an instance of RangeIndex class with specified DataType.

Here is an example to create RangeIndex instance passing in the DataType:

RangeIndex rangeIndex = Index.Range(DataType.Number);
</code></pre></p>

Parameters:

dataType - the data type.

Returns:

an instance of RangeIndex type.

Range

public static RangeIndex Range(DataType dataType, int precision)

Returns an instance of RangeIndex class with specified DataType and precision.

Here is an example to create RangeIndex instance passing in the DataType and precision:

RangeIndex rangeIndex = Index.Range(DataType.Number, -1);
</code></pre></p>

Parameters:

dataType - specifies the target data type for the index path specification.
precision - specifies the precision to be used for the data type associated with this index.

Returns:

an instance of RangeIndex type.

Spatial

public static SpatialIndex Spatial(DataType dataType)

Returns an instance of SpatialIndex class with specified DataType.

Here is an example to create SpatialIndex instance passing in the DataType:

SpatialIndex spatialIndex = Index.Spatial(DataType.Point);

Parameters:

dataType - specifies the target data type for the index path specification.

Returns:

an instance of SpatialIndex type.

Applies to