Is there any annotation for creating indexes in Cosmos document?

In JPA we can create indexes for the entity using annotations like –
@Table(indexes = @Index(columnList = "firstName"))

Do we have a similar way of creating indexes for the Cosmos DB?

>Solution :

With Spring data cosmos, you can define custom indexing policy using @CosmosIndexingPolicy annotation for your container.


@Container(containerName = "users")
        includePaths = {
        excludePaths = {
public class UserDocument {
    private String id;

    private String name;

Javadoc for more reference:$web/java/azure-spring-data-cosmos-core/3.0.0-beta.1/index.html?com/azure/spring/data/cosmos/core/mapping/CosmosIndexingPolicy.html

Leave a Reply