Reputation: 1898
I have a collection where the documents have different kind of properties like Strings, Numbers, DateTimes.
And the indexing policy I have is like following:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": []
}
Now what I want, is to adding Range type indexing on the String fields as well. So I edited my indexing policy like:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
},
{
"kind": "Range",
"dataType": "String",
"precision": 20
}
]
}
],
"excludedPaths": []
}
But it did not work :(
I know multiple type indexing can be added on a field. Can anyone have any idea how to do that?
Upvotes: 1
Views: 105
Reputation: 8003
For a given data type, you can have only one index type (Hash or Range) for a specified path. Also Range is a superset of Hash in terms of queries that are supported. Hash supports only equality queries, but Range supports equality, range, and order by queries.
So you just need to remove the JSON block for Hash on String, e.g. like the following and the indexing policy update will succeed:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": 20
}
]
}
],
"excludedPaths": []
}
Upvotes: 1