Tuesday, October 8, 2019

How to exclude property Paths in Azure Cosmos DB Indexing Policy


     Selecting right indexes is very important task in any database system. Azure Cosmos DB indexes every attribute in an object by default. Selecting right indexes to exclude becomes very important task in Azure Cosmos DB.

     If everything is indexed already; Why do we want to exclude some of indexes? Indexes are saved on disk, you pay for the storage in Azure. If you keep indexing everything, your index file gets larger and you pay more for storage.

     Also; write operations to index file takes longer if index file is larger. By keeping only what you need in index file will improve the latency of write operations. If you will need to change your indexing policies, Rebuilding indexes will take less time.

     I have the following document in my database, and some of the properties of this document should not be indexed. For example; PostBody is a great example. I will never search by PostBody and it is the largest value in this document too. I should save good amount of disk space by excluding it.
      To exclude PostBody property, I need to go to the Scale & Settings option under my collection.


     I add the PostBody property path to exludedPaths. To declare a path leading to a scalar value like PostBody, you need to write its path and end the path with /?  You can declare an array path by adding /[] to the end of an array path.

Here is what my excludedPaths looks like after I add PostBody exclusion to my excludedPaths list.

When you are done editing Indexing Policy, Click on Save button Reindex your collection.



No comments:

Post a Comment