[Clarifications] Difference between @PartitionKey (Spring annotation) and partition_key_path (Container parameter)

Francesco Cesareo 56 Reputation points
2022-06-10T19:07:21.817+00:00

Hi all,
I don't understand the difference between partition_key_path that I should set during container creation and the Spring annotation @PartitionKey used when I define an entity in my app.

Which is the relationship between the two modes?

In my case, I don't have nested keys, but I need to partition on a base field (ie. firstName), so I set it (ie /firstName) as partition_key_path. Then do I annotate firstName field with @PartitionKey in my code too? or is it unnecessary?

I read in this article (https://learn.microsoft.com/en-us/java/api/overview/azure/spring-data-cosmos-readme?view=azure-java-stable#nested-partition-key-support) that @PartitionKey annotation takes precedence versus partitionKeyPath defined in the @Container. Is it the same case of partition_key_path defined at Container definition context? If yes, in this case I could leave /id as partition_key_path and manage partitioning at applicative level.

Thank you for the support.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,454 questions
Azure Spring Apps
Azure Spring Apps
An Azure platform as a service for running Spring Boot applications at cloud scale. Previously known as Azure Spring Cloud.
110 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anurag Sharma 17,576 Reputation points
    2022-06-13T05:12:53.947+00:00

    Hi @Francesco Cesareo , welcome to Microsoft Q&A forum.

    You are right in mentioning that @partitionkey annotation takes precedence when defined. Also the same article mentions that partitionKeyPath should only be used to support nested partition key path. For general partition key support, use the @PartitionKey annotation.

    210617-image.png

    So if you dont have the nested key path, you can choose to use @partitionkey annotation.

    Please let us know if this helps or else we can discuss more on this.


0 additional answers

Sort by: Most helpful