我需要将Azure CosmosDB(以前称为DocumentDB)中的数据移动到Azure SQL数据库中。
我正在使用“复制数据”资源,我已经设置了源和目标以及映射。
时间表已经设置为每小时一次。问题 :
活动Copy_dbo_SubscriptionLocator失败:“源”端发生故障。 ErrorCode = UserErrorDocumentDBReadError,'Type = Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message = DocumentDb操作失败:消息:{“错误”:[“指定了一个无效的查询,其中包含针对不是范围的路径的过滤器 - 索引。考虑在请求中添加允许扫描标头。“]}
我需要对CosmosDB进行哪些更改以避免错误?
以下是我目前的索引政策:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
],
"excludedPaths": [
{
"path": "/OneOfTheColumns/*"
}
]
}
看起来问题在于datetime字段,需要将其作为字符串进行范围索引。我可以在文档中使用_ts字段。但是,如何更改“复制”作业以将查询的日期时间转换为纪元时间,并将其值用于_ts字段。
我不确定您使用的是哪种语言,所以我将您的问题转发给我,请参阅我的步骤。
我的样本文件:
[
{
"id": "1",
"name": "Jay",
"course": "A",
"score": 50
},
{
"id": "2",
"name": "Peter",
"course": "B",
"score": 20
}
]
指数政策:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/name/?",
"indexes": [
{
"kind": "Hash",
"dataType": "String",
"precision": 3
},
{
"kind": "Range",
"dataType": "Number",
"precision": -1
}
]
}
],
"excludedPaths": [
{
"path": "/*"
}
]
}
查询来源:(SELECT c.id,c.name,c.course,c.score FROM c where c.score>30)
重现您的问题:
Range支持高效的相等查询,范围查询(使用>,<,
=,<=,!=)和ORDER BY查询。 ORDER默认情况下,查询还需要最大索引精度(-1)。数据类型可以是String或Number。
如果您有范围查询,则需要在字段上定义范围索引。请参考官方doc。
所以,我修改了上面的索引策略并成功复制了数据:
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Spatial",
"dataType": "Point"
}
]
}
],
"excludedPaths": []
}
希望它能帮到你。