即使已为JSON编制索引,查询中是否仍需要分区键 [英] Is partition key needed in queries even though JSON is indexed

查看:98
本文介绍了即使已为JSON编制索引,查询中是否仍需要分区键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正计划使用Cosmos Db(文档Db),并且试图了解查询,索引和分区之间的相互关系.

I'm planning on using Cosmos Db (Document Db) and I'm trying to understand how the queries, indexing and partitions relate to each other.

如何在Azure Cosmos Db中进行分区和扩展讨论分区键和其他文档表明分区键+ id =文档的唯一ID.但是随后 Azure Cosmos Db中的SQL查询和SQL语法它提供了JSON文档的自动索引,而无需显式的架构或创建二级索引.

How to partition and scale in Azure Cosmos Db talks about the partition key and other documentation indicates that partition key + id = unique id for the document. But then SQL Query and SQL syntax in Azure Cosmos Db says it provides automatic indexing of JSON documents without requiring explicit schema or creation of secondary indexes.

我知道分区键对于可伸缩性和数据存储方式非常重要.但是,如果我们考虑进行搜索,那么分区键就像是额外的filter/where子句吗?所有文档都已建立索引,因此我可以执行以下查询:

I understand that partition key is important for scalability and how data is stored. But if we think about searching is the partition key kind of like extra filter/where clause? All the documents are indexed so I can execute query like:

SELECT * 
FROM Families
WHERE Families.address.state = "NY"

在使用这种SQL查询语法时,我还是应该指定分区键或说明如何允许跨分区查询?

Should I still specify the partition key or indicate some how that cross partition queries are allowed when using this SQL query syntax?

推荐答案

您的第一个链接给出了答案:

Your first link gives the answer for this:

对于分区集合,可以使用PartitionKey对单个分区运行查询(尽管Cosmos DB可以从查询文本中自动提取该查询),而EnableCrossPartitionQuery可以对多个分区运行查询.

For partitioned collections, you can use PartitionKey to run the query against a single partition (though Cosmos DB can automatically extract this from the query text), and EnableCrossPartitionQuery to run queries that may need to be run against multiple partitions.

是的,您需要指定WHERE子句以使查询针对单个分区运行,或者在查询选项中将EnableCrossPartitionQuery设置为true.

So, yes, you either need to specify the WHERE clause which will make query run against a single partition, or set EnableCrossPartitionQuery to true in query options.

这篇关于即使已为JSON编制索引,查询中是否仍需要分区键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆