Join Chander Dhall for an in-depth discussion in this video Alter indexing strategy dynamically, part of Cosmos DB Developer Deep Dive.
- [Instructor] So, now that we've seen this, I just want to show you some very simple hacks you could do to change your indexing policy on the fly. So, for example, you have the collection. (clicking) You could do something like collection.Resource and then you can have it indexing policy. And then take the indexing mode and change this to, let's say, lazy. Now one thing you'll notice is that it's very hard to reproduce a lazy indexing mode when you're doing some kind of demos.
'Cause it's usually instantaneously fast and that's because you don't have a lot of requests coming in. But you will definitely see a difference in that indexing mode versus consistent, when you have a lot of data that's being written` to the azure cosmos DB collection that you're working with. So this may not be something you might see in demos or development code, but that does not mean that it's as fast as consistent. And you could have done something same way, you could have changed this to consistent or lazy, and that's one way you can change the indexing policy dynamically.
At the same time, very similarly, you could take this and, on the fly, create a new indexing policy that will now override the previous one and actually set new range index and then come up with the data type of your choice. As you can see, there are very different data types that are supported here. We can have a point. We have a polygon. We can also have number, linestring, or even something like string that we used earlier. Another thing to keep in mind is that precision is maximum when it is minus one.
So that's by default and it's a good way to do indexing with maximum precision. And that's just a typo that was in indexing policy and that actually is the indexing policy.
- Data import scenarios
- Creating a database
- Creating a partitioned collection
- Data manipulation
- Importing documents with a stored procedure
- User-defined functions
- Excluding indexing at a document level
- Range indexing on strings
- Querying with SQL parameters
- Range operations