Reputation: 40032
I am trying to remove the default indexes which are created for a new collection:
{
"indexingMode": "lazy",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
},
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": []
}
As far as I understand, this will index every attribute in every resource and its sub-resources.
When attempting to exclude everything using this:
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath
{
Path = "/*"
});
client.ReplaceDocumentCollectionAsync(collection).Wait();
I get the following error on ReplaceDocumentCollectionAsync()
:
The indexing path '/*' could not be accepted. Please ensure that the path is unique across all sets of indexing paths and it's valid.
I want to be able to define my own, custom, index paths. In order to do this, I need to remove the default indexes (which index everything).
I have removed the index by assigning the includes to an empty collection AND by excluding all paths:
collection.IndexingPolicy.IncludedPaths = new Collection<IncludedPath>();
collection.IndexingPolicy.ExcludedPaths = new Collection<ExcludedPath>();
collection.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath
{
Path = "/*"
});
Note 1: For some reason, if only doing the first statement, nothing changes on the index policy... and without error.
Note 2: ExcludePaths
has to be set to an empty collection initially or else (if the path already exists) it will detect the conflict and throw a error (when doing a ReplaceDocumentCollectionAsync of course).
Indexing document:
{
"indexingMode": "lazy",
"automatic": true,
"includedPaths": [
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": [
{
"path": "/*"
}
]
}
I assume that the /_ts/?
path is mandatory.
Upvotes: 4
Views: 3453
Reputation: 2728
An easy way to exclude everything would be to switch indexingMode: None
Upvotes: 2
Reputation: 8119
Sounds like you've pretty much figured it out. To clarify, id
and _ts
are treated as special properties in regards to indexing.
id
is implicitly treated as the document's primary key - in which, id
will always be indexed with uniqueness enforced.
_ts
is an epoch timestamp of when a document was last written (create or replace), and will also always be indexed. This property will be explicitly noted within the index policy.
The following indexing policy illustrated how to index only the document.prop.subprop
property (along with id
and _ts
):
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/prop/subprop/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
}
]
},
{
"path": "/\"_ts\"/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": [
{
"path": "/*"
}
]
}
Upvotes: 4