Home > OS >  Is there any annotation for creating indexes in Cosmos document?
Is there any annotation for creating indexes in Cosmos document?

Time:06-22

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?

CodePudding user response:

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

Example:

@Container(containerName = "users")
@CosmosIndexingPolicy(
        includePaths = {
                "/name/?"
        },
        excludePaths = {
                "/*"
        }
)
public class UserDocument {
    @Id
    @GeneratedValue
    @PartitionKey
    private String id;

    private String name;
}

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

  • Related