Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading