- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么 CosmosDB 默认情况下不索引数组?默认索引路径是
"path": "/*"
这不是意味着“索引所有内容”吗?不是“索引除数组之外的所有内容”。
如果我将数组字段添加到索引中,如下所示:
"path": "/tags/[]/?"
它将工作并开始索引该特定数组字段。
但我的问题是为什么“索引所有内容”不索引所有内容?
编辑:这是一篇描述我所看到的行为的博客文章。 http://www.devwithadam.com/2017/08/querying-for-items-in-array-in-cosmosdb.html Array_Contains查询非常慢,显然没有使用索引。如果您将相关字段显式添加到索引中,则查询速度会很快(显然它们开始使用索引)。
最佳答案
如 Index Types 中所述
Azure Cosmos containers support a new index layout that no longer usesthe Hash index kind. If you specify a Hash index kind on the indexingpolicy, the CRUD requests on the container will silently ignore theindex kind and the response from the container only contains the Rangeindex kind. All new Cosmos containers use the new index layout bydefault.
以下问题不适用于新的索引布局。默认索引策略运行良好(并以 36.55 RU
提供结果)。然而,现有的集合可能仍在使用旧的布局。
我能够使用 ARRAY_CONTAINS
重现您所询问的问题。
设置一个包含来自 SO 数据转储的 100,000 个帖子的 CosmosDB 集合(例如,这个问题将如下所示)
{
"id": "50614926",
"title": "Indexing arrays in CosmosDB",
/*Other irrelevant properties omitted */
"tags": [
"azure",
"azure-cosmosdb"
]
}
然后执行以下查询
SELECT COUNT(1)
FROM t IN c.tags
WHERE t = 'sql-server'
该查询使用默认索引策略占用了 2,000 多个 RU,添加了以下内容则占用了 93 个 RU(如链接文章中所示)
{
"path": "/tags/[]/?",
"indexes": [
{
"kind": "Hash",
"dataType": "String",
"precision": -1
}
]
}
但是,您在这里看到的不是默认情况下不对数组值建立索引。只是默认范围索引对您的查询没有用。
范围索引使用基于部分前向路径的键。因此将包含如下路径。
标签/0/azure
标签/0/c#
标签/0/oracle
标签/0/sql-server
tags/1/azure-cosmosdb
标签/1/c#
tags/1/sql-server
使用此索引结构,它从 tags/0/sql-server
开始,然后读取所有剩余的 tags/0/
条目以及整个条目tags/n/
其中 n
是大于 0
的整数。需要检索和评估映射到其中任何一个的每个不同文档。
相比之下,哈希索引使用反向路径 ( more details - PDF )
StackOverflow 理论上允许 UI 为每个问题添加最多 5 个标签,因此在这种情况下(忽略一些问题通过网站管理事件拥有更多标签的事实),感兴趣的反向路径是
sql-server/0/tags
sql-server/1/tags
sql-server/2/tags
sql-server/3/tags
sql-server/4/tags
通过反向路径结构,查找叶节点值为 sql-server 的所有路径是直接的。
在此特定用例中,由于数组最多有 5 个可能值,因此还可以通过仅查看这些特定路径来有效地使用原始范围索引。
以下查询在我的测试集合中使用默认索引策略占用了 97 个 RU。
SELECT COUNT(1)
FROM c
WHERE 'sql-server' IN (c.tags[0], c.tags[1], c.tags[2], c.tags[3], c.tags[4])
关于azure - CosmosDB 中的索引数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50614926/
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4年前关闭。 Improve t
我在我的 CosmosDB 集合中创建了一个简单的 Pre Trigger。 function testTrigger() { var context = getContext();
我正在尝试扁平化和过滤 CosmosDB 中的 json 数据。 数据如下所示,我想展平数组变量中的所有内容,然后按数组内的特定 _id 和时间戳进行过滤: { "_id": 21032, "Firs
我正在测试 CosmosDb。我发现初始连接通常需要很多秒。我编写了一个小型 .net core 2.2 控制台应用程序来演示该问题。 static async System.Threading
我正在测试 CosmosDb。我发现初始连接通常需要很多秒。我编写了一个小型 .net core 2.2 控制台应用程序来演示该问题。 static async System.Threading
我有很多(大约 100 条)数据要与 CosmosDB 中的文档相关联。每条数据都很小(大约 100 个字节)。 我的第一个解决方案是将数据作为数组存储在文档中。这可以正常工作,但是为了将新项目附加到
据我所知,团队的官方建议是将所有数据类型放入单个集合中,例如 type=someType文档上的字段以区分类型。 现在,如果我们假设具有分区的大型数据库,其中不同的对象类型可以是: 完全不同的字段(因
这是我们要存储的示例文档: { "name": "Joe Bloggs", "locations": [ { "type": "Point", "coordinates": [1,1] }, { "t
是否可以获得的大小?每 Cosmos DB 集合中的分区?我知道门户会在 Metrics Blade 中显示集合中的前几个分区,但我对查看每个分区的大小很感兴趣。 最佳答案 我相信您应该能够通过 Co
我试图在 Cosmos 中拥有多个文档,一旦提交,其中一个将保存提交表单中的一些数据。我正在尝试使用其他一些文档来保存下拉选择列表的数据。我如何能够连接到多个 config.containerId 以
我想做一个这样的查询 g.V().match( as('foo').hasLabel('bar'), as('foo').out('baz').hasId('123'), as('foo'
我正在尝试使用以下查询来查看数据库中是否有重复项 SELECT c.VariantNo, count(1) AS jongel FROM c where c.brand = 'XXXX' AND c.
我有一个包含许多字段的大型文档,我只想从对象返回 1-2 个字段以保持吞吐量。这在 cosmosDB 中可能吗?还是我每次都需要返回整个对象? 最佳答案 使用 ReadItemAsync() 进行点读
我有一个 CosmosDB 查询: SELECT food.tags FROM food 返回这个: { "tags": [ { "name": "babyfood"
想象一下我们有一个这样的集合(示例取自 https://www.documentdb.com/sql/demo ) { "_id" : "19015", "description" :
我正在使用 MongoDB api 访问 Azure 上的 CosmosDb。我收集了数千份文件。 它们的形状是这样的: { "_id" : ObjectId("5b4f574ac2100c8
我正在尝试在 CosmosDB 中实现以下查询: SELECT * FROM c WHERE c.timestamp = (SELECT VALUE MAX(c.timestamp) FROM c )
我们可以在 cosmos Db 中添加 XML Schema 吗?如果是,我们如何查询它们?我可以将 XML 数据保存为字符串,但如何查询它们? 下面是我收藏的文档: { "id":
我研究了几个地方,但找不到有关将旧数据从 cosmosdb 存档到冷存储的选项的任何方向。我看到 AWS 中的 DynamoDb 提到您可以将 dynamodb 数据移动到 S3 中。但不确定 cos
取自:https://learn.microsoft.com/en-us/azure/cosmos-db/create-graph-dotnet 我在 .wait() 部分遇到异常: NullR
我是一名优秀的程序员,十分优秀!