Introduction
By default, the Azure Cosmos DB data is indexed. Azure applies its default indexing policy while creating a collection. However, the users can set their customized indexing policy as per the requirement.
Types of Index
- Hash - Supports efficient equality queries.
- Range - Supports efficient equality queries, range queries, and order by queries
- Spatial - Supports efficient spatial (within and distance) queries. The datatype can be Point, Polygon, or LineString.
The process of customizing the Indexing Policy
- Login to Azure Portal.
- Go to the Azure Cosmos DB account.
- Go to Settings.
- Select Collection
- Click on Indexing Policy.
- Update the policy as per your requirement.
Default Indexing Policy
When creating a collection using the Azure portal, the Cosmos DB indexes both, strings and numeric properties, by default, with Range Index.
- String Properties - Range Indexed
- Numeric Properties - Range Indexed
- Spatial - Point Indexed

When creating a collection by code, Azure Cosmos DB, by default, indexes all the string properties within document consistently with a Hash index, and numeric properties with a Range index.
- String Properties - Hash Indexed
- Numeric Properties - Range Indexed

Indexing Modes
- Consistent
- Indexes get updated synchronously on each insert, update, and delete operation.
- Designed for “write quickly, query immediately”
- Incurs highest request unit charge per write
- Lazy
- Index updates asynchronously
- Designed for “ingest now, query later”
- Useful when data is written in a burst
- You might get inconsistent results for COUNT queries
- None
- Useful if no index is associated with the document
- Commonly used if Cosmos DB is utilized as key-value storage and documents are accessed only by their Id Property.

Join the conversation! Your thoughts help the community grow.