仅Cosmos DB表API索引PartitionKey和RowKey

时间:2018-11-23 02:31:57

标签: azure-cosmosdb azure-cosmosdb-tables

在Cosmos DB中使用TablesDB表,我试图仅索引PartitionKey和RowKey。

下面的我的CosmosDB索引可以正确编译,但是当我在PartitionKey / RowKey上运行查询时,出现错误“为索引中排除了路径的过滤器指定了无效的查询。请考虑在请求中添加允许扫描标头。”

有人知道如何使用仅索引PartitionKey和RowKey而不索引其他内容的CosmosDB TablesDB吗?

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/PartitionKey/?",
            "indexes": [
                {
                    "kind": "Hash",
                    "dataType": "String",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                }
            ]
        },
        {
            "path": "/RowKey/?",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "String",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                }
            ]
        }
    ],
    "excludedPaths": [
        {
            "path": "/*"
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

我们使用几乎相同的索引配置,只是将'?'字符更改为'*'。我们的配置如下:

{
    "indexingMode": "lazy",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/PartitionKey/*",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "String",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                }
            ]
        },
        {
            "path": "/RowKey/*",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "String",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                }
            ]
        }
    ],
    "excludedPaths": [
        {
            "path": "/*"
        }
    ]
}