The first time a record is inserted, every property is indexed. Each time the record is updated, the entire json is replaced, and so every property is freshly indexed, as it may have changed. Changes are not done to just one property. This indexing is expensive, so to speak, because it happens on every write for every property. If properties are rarely, or never updated, (the info is generated and then frozen, like a cash register receipt) then it really doesn't increase the cost very much. But if it is "write heavy" then you want to ensure your indexes only cover what is actually being queried. The other indexes are not necessary and thus can be excluded. In a SQL database, the opposite strategy is taken: Index nothing, unless it is manually done. In Cosmos, it is more developer friendly to index everything and then fine tune it from there.
Great Info, Thanks team👍
is it same cosmos MongoDB?
Why is indexing all properties expensive? Giving a little info on this would give users an idea of why thinking of indexes is important
As he said... It is only expensive for writing operations (because all affected indexes have to be changed).
The first time a record is inserted, every property is indexed. Each time the record is updated, the entire json is replaced, and so every property is freshly indexed, as it may have changed. Changes are not done to just one property. This indexing is expensive, so to speak, because it happens on every write for every property. If properties are rarely, or never updated, (the info is generated and then frozen, like a cash register receipt) then it really doesn't increase the cost very much. But if it is "write heavy" then you want to ensure your indexes only cover what is actually being queried. The other indexes are not necessary and thus can be excluded. In a SQL database, the opposite strategy is taken: Index nothing, unless it is manually done. In Cosmos, it is more developer friendly to index everything and then fine tune it from there.
2 RUs being cheap is relative, for example if you make thousands of queries per day, 2 RUs might not be cheap. Wish the presenter talked about this
RUs are Request units per second. So, a thousand queries is still pretty cheap if it is per day