This particular guide focuses on achieving this task using the Azure portal which can be a significant area of focus for the DP-420 Exam: Designing and Implementing Native Applications Using Microsoft Azure Cosmos DB.

Table of Contents

Indexing in Azure Cosmos DB

Before we delve into how to configure a custom indexing policy, it’s essential to understand what indexing is and how it works in Azure Cosmos DB. Essentially, an index allows Azure Cosmos DB to provide efficient and fast access to data by defining a path within your data. By default, Azure Cosmos DB automatically indexes all properties in all items within a container. However, in specific situations, you may want to override these default settings with a custom indexing policy.

Why Configure a Custom Indexing Policy?

The goal of a custom indexing policy is to optimize the balance between write and read performance, storage usage, and index freshness. A well-configured indexing policy can lead to reduced latency, lower Request Unit (RU) charges, and improved application performance.

Configuring a Custom Indexing Policy Using Azure Portal

To create a custom indexing policy, follow the steps below:

  • Log in to the Azure portal.
  • Navigate to the Azure Cosmos DB account in which you want to configure a custom indexing policy.
  • Next, select the desired container for which the custom indexing policy will be set.
  • In the Settings blade, click on the ‘Scale & Settings’, then ‘Indexing Policy’.
  • Here you can customize your indexing policy. An essential aspect of configuring a custom indexing policy is including and excluding paths. Inclusion of paths makes Azure Cosmos DB index certain item properties, thereby allowing efficient queries on these properties. Exclusion of paths, on the other hand, excludes certain properties from being indexed, thus reducing storage and write costs.

For example, consider the indexing policy below:

{
“indexingMode”: “consistent”,
“automatic”: true,
“includedPaths”: [
{
“path”: “/includePath1/?”,
“indexes”: [
{
“dataType”: “Number”,
“precision”: -1
}
]
}
],
“excludedPaths”: [
{
“path”: “/excludePath1/?”
}
]
}

This policy configures Azure Cosmos DB to index every property in all items in the container bar one: i.e., every property specified in the path “/excludePath1/.” It also commands Azure Cosmos DB to pay special attention to “/includePath1/?,” assigning a data type of ‘Number’ with a precision of ‘-1’.

Remember, before you proceed to save, ensure to thoroughly understand the implications of the policy to your RU costs and application performance.

Default Indexing Policy Vs. Custom Indexing Policy

A comparison between the default indexing policy and a custom indexing policy could look something like this:

Policy Included Paths Excluded Paths Automatic Indexing Mode
Default All None True Consistent
Custom User-defined User-defined User-defined User-defined

In conclusion, customizing the indexing policy in Azure Cosmos DB can improve your application’s efficiency and performance while also reducing resource utilization and costs. It is a crucial skill, and understanding how it works is beneficial for users preparing for the DP-420 exam.

Practice Test

True or False: The Azure portal allows you to configure a custom indexing policy.

  • True
  • False

Answer: True

Explanation: The Azure portal has a feature that allows you to configure a custom indexing policy which can help in improving the performance of your Azure Cosmos DB.

True or False: You cannot define your own indexing policy in Azure Cosmos DB.

  • True
  • False

Answer: False

Explanation: Azure Cosmos DB allows you to define your own indexing policy. This feature gives you the flexibility to index the data according to your needs.

Which of the following is not an option for indexing in Azure Cosmos DB?

  • a) Consistent
  • b) Reliable
  • c) Lazy
  • d) None

Answer: b) Reliable

Explanation: Azure Cosmos DB offers three indexing modes – Consistent, Lazy, and None. There is no option as ‘Reliable’.

True or False: The throughput cost of an operation in Azure Cosmos DB is directly proportional to the Indexing Mode that is defined.

  • True
  • False

Answer: True

Explanation: The throughput cost of an operation in Azure Cosmos DB is directly influenced by the Indexing Mode. The more intensive the mode, the higher the cost.

True or False: All properties are automatically indexed in Azure Cosmos DB.

  • True
  • False

Answer: True

Explanation: By default, Azure Cosmos DB automatically indexes all properties in all items within your container.

What is used in Azure Cosmos DB to exclude paths from an index to improve write performance?

  • a) Throughput Constraint
  • b) Lazy Indexing
  • c) Excluded Paths
  • d) Tunneling Paths

Answer: c) Excluded Paths

Explanation: Excluded paths are used in Azure Cosmos DB to prevent specific paths from being indexed, thus improving write performance.

True or False: Changing an indexing policy does not affect the availability of the Azure Cosmos DB data.

  • True
  • False

Answer: False

Explanation: Changing an indexing policy in Azure Cosmos DB can affect the availability of the data. This is due to the fact that changing the indexing policy triggers a re-indexing of the data.

Which among the following cannot be done using Azure portal with respect to Indexing policies in Azure Cosmos DB?

  • a) View the indexing policy of a container
  • b) Modify the indexing policy of a container
  • c) Delete the indexing policy of a container
  • d) Create an indexing policy for a container

Answer: c) Delete the indexing policy of a container

Explanation: Azure portal allows you to view, modify and create an indexing policy for a container but doesn’t allow you to delete it.

True or False: It is mandatory to specify the include and exclude paths when defining a custom indexing policy.

  • True
  • False

Answer: False

Explanation: Specifying the include and exclude paths when defining a custom indexing policy is optional. Moreover, all paths are included by default if not specified.

True or False: The included paths are case-insensitive.

  • True
  • False

Answer: True

Explanation: The included paths in the indexing policy are case-insensitive. The paths “/name” and “/Name” would be considered the same.

Which of the following is an example of a valid included path in an indexing policy?

  • a) /name/?/
  • b) /name/[]/
  • c) PC/name/
  • d) /name/?

Answer: a) /name/?/

Explanation: The wildcard “?” in /name/?/ stands for a single level in the path and is used to index specific paths.

Which of the following denotes a wildcard in the path of an indexing policy in Azure Cosmos DB?

  • a) *
  • b) []
  • c) ?
  • d) {}

Answer: c) ?

Explanation: The “?” is used as a wildcard and denotes any single level in a path while configuring an indexing policy in Azure Cosmos DB.

What is the maximum limit on the number of included and excluded paths in an indexing policy in Azure Cosmos DB?

  • a) 50
  • b) 100
  • c) 200
  • d) No limit

Answer: c) 200

Explanation: The maximum number of combined included and excluded paths in an indexing policy for Azure Cosmos DB is

True or False: You can exclude all subpaths under a single root by excluding the root path.

  • True
  • False

Answer: True

Explanation: Excluding the root path will effectively exclude all subpaths underneath that root, allowing you to efficiently prevent indexing of unneeded data.

True or False: Azure Cosmos DB supports composite indexing.

  • True
  • False

Answer: True

Explanation: Composite indexing is a feature of Azure Cosmos DB to allow for more efficient queries by including multiple properties in an index.

Interview Questions

What is the purpose of configuring a custom indexing policy in Microsoft Azure Cosmos DB?

The purpose of configuring a custom indexing policy is to optimize read and write performance for specific query patterns and to manage the storage overhead associated with the index.

How do you create a custom indexing policy in Azure portal?

On Azure portal, under the Settings section of your Cosmos DB account, you can use the Indexing Policy editor to create a custom indexing policy.

What are some factors to consider when designing a custom indexing policy?

Some factors to consider are the types of queries you will be executing, frequency of updates and inserts, and the trade-off between the storage and throughput cost of indexing versus the performance benefits for query workloads.

What is the impact of the “Included Paths” setting in Azure Cosmos DB indexing policy?

“Included Paths” determines which document paths to include in the index. Including a path will allow you to filter and/or sort on that path in your queries.

Can you modify an existing index policy in Azure Cosmos DB?

Yes, you can modify the existing index policy. However, changes to the index policy will trigger a reindexing of your existing data.

What happens if you don’t set any custom indexing policy?

If you don’t set any custom indexing policy, Azure Cosmos DB will apply a default policy that indexes every property in your documents.

Can you exclude a certain path from the index in Cosmos DB?

Yes, under the “Excluded Paths” section of the index policy, you can specify paths that you do not want to be indexed.

How are the changes to the indexing policy reflected?

The changes to the indexing policy are applied as a background operation. The time it takes to reflect the changes depends on the size and distribution of your data.

What is the role of the “Indexing Mode” setting in the indexing policy of Azure Cosmos DB?

The “Indexing Mode” allows you to control the trade-off between write latency and query consistency.

How does the ‘index transformation progress’ impact the working of Cosmos DB?

The ‘index transformation progress’ gives you the percentage completion status of a transform. It impacts the working by consuming some write capacity on the container until the transformation is complete.

Can the custom indexing policy be configured using Azure Cosmos DB SDKs?

Yes, the custom indexing policy can also be configured using Azure Cosmos DB SDKs besides the Azure portal.

What does setting the Automatic flag to true in Azure Cosmos DB’s indexing policy do?

Setting the Automatic flag to true in Azure Cosmos DB’s indexing policy enables automatic indexing. This means that new and updated items will be automatically indexed.

What is the function of the Indexed field in Azure Cosmos DB’s indexing policy?

The Indexed field in Azure Cosmos DB’s indexing policy determines if the documents within the path are indexed or not.

What is the purpose of an ‘Indexing Directive’ in an Azure Cosmos DB’s indexing policy?

The purpose of an ‘Indexing Directive’ is to control if and how a specific write action (create, replace, upsert) should be indexed.

Can you adjust the indexing precision in Azure Cosmos DB?

Yes, the precision of range and spatial indexing can be adjusted by setting the ‘Precision’ property in your indexing policy.

Leave a Reply

Your email address will not be published. Required fields are marked *