【发布时间】:2019-05-27 07:55:34
【问题描述】:
我正在使用 Java SDK 编写数据库创建脚本,但未按预期创建索引策略(和 documented)。
- 使用的 JAVA SDK:
com.microsoft.azure:azure-documentdb:2.4.0 - 适用于 Windows 的 Azure Cosmos DB 模拟器 2.2.2
- 当前使用 SQL 帐户在 Azure 门户中安装 Cosmos DB
我使用 JAVA 库构建集合创建请求,结果(在实际请求之前)如下所示 (DocumentCollection::toJson()):
{
"uniqueKeyPolicy": {},
"partitionKey":
{
"kind": "Hash",
"paths": ["/playerId"]
},
"indexingPolicy":
{
"indexingMode": "Consistent",
"automatic": true,
"includedPaths": [
{
"path": "/gameId/?",
"indexes": [
{
"kind": "Range",
"dataType": "String"
}
]
},
{
"path": "/playerId/?",
"indexes": [
{
"kind": "Range",
"dataType": "String"
}
]
},
{
"path": "/date/*",
"indexes": [
{
"kind": "Range",
"dataType": "String"
}
]
}
],
"excludedPaths": [
{
"path": "/*"
}
]
},
"id": "Games"
}
请求成功完成,但如果我使用数据浏览器或DocumentClient.readCollection 检查实际的索引策略,它看起来像这样:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/gameId/?",
"indexes": []
},
{
"path": "/playerId/?",
"indexes": []
},
{
"path": "/date/*",
"indexes": []
}
],
"excludedPaths": [
{
"path": "/*"
},
{
"path": "/\"_etag\"/?"
}
]
}
如您所见,索引定义的数组为空。 然后,如果我从 SDK 生成的输出中复制索引策略并将其手动粘贴到模拟器或门户“缩放和设置”窗口中以创建集合,则更新结果如下:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/gameId/?",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
},
{
"path": "/playerId/?",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
},
{
"path": "/date/*",
"indexes": [
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
}
],
"excludedPaths": [
{
"path": "/*"
},
{
"path": "/\"_etag\"/?"
}
]
}
因此正在创建索引(尽管有额外的Number 条目,如提到的here)。
我的创建脚本有问题吗?
【问题讨论】: