Guilherme
Guilherme

Reputation: 5341

Should I index my PartitionKey when using cosmosDB

I'm new to Cosmos DB and I am wondering if I should create an index for my PartitionKey. For example, let's suppose I choose a non-unique ID to be my partition key. Here are some sample data:

uniqueId someProperty partitionKey
1 some data 1
2 some more data 1
3 some more data 1
4 some more data 2
5 some more data 2

And let's assume I want to query all the items that have partitionKey = 2. Should I add an index on partitionKey, or this column is optimized just by the fact that it is partitioned?

Upvotes: 2

Views: 705

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222522

If you are asking about if you need to index it manually, Cosmos DB automatically indexes every property for all items. If you are talking about explicitly adding index policy then Yes, if you have disabled default indexing policy and need to filter by partition key then you should add an index to it.

Upvotes: 4

Related Questions