我的收藏的Azure Cosmos DB索引策略 [英] Azure Cosmos DB indexing policy for my collection
问题描述
我是Cosmos DB的新手,我正在将传感器数据推送到IoT中心,然后再推送到Cosmos DB.
Hi I am new to Cosmos DB , I am pushing my sensor data to IoT hub and then to Cosmos DB .
以下哪种格式最好将其存储在宇宙中以增加读取和写入的吞吐量,因为在每条记录中,我将具有150个传感器和
which of the following format will be better one to storing the data in cosmos to increase the throughputs of reads and writes as in each record i will be having 150 number of sensors and
几乎所有我对DeviceId的查询(这也是分区键).和currentTime
And Almost all my queries on DeviceId ( which is partition key also ) . and currentTime
{
"DeviceId" : 1234 ,
"sensor1" : 234,
"sensor3" : 4,
....
....
"currentTime" : 121212
}
{
"DeviceId" : "asad",
"currentTime" : 1212123,
"data" : {
"sensor1" : 323,
"sensor2" : 234,
"sensor3" : 444,
......
......
}
}
据我所知,如果我使用第一个,它将索引每个键,并且读写操作会很昂贵,因为 甚至我将索引Path都保留为/,因为所有索引都处于同一级别,每个键都将是索引.
As I know if I use first one it will index each key and reads and writes will be costly , as even I keep include index Path as / , as all are at same level each key will be index .
如果我使用第二个,我将只能控制仅对一个索引编制索引并排除对/data的索引编制?
If i use second one i will have control over to index only only one level and Exclude indexing of /data?
任何建议,因为我对cosmos DB相对较新.
Any suggestion as i am relatively new to cosmos DB.
推荐答案
您好,Amjathkhan,
Hi Amjathkhan,
请在上阅读 索引路径.我将在您的第二个Json示例中使用类似下面的内容,但是取决于如果您的Json和分区集合中有数组等.
Please read-up on Index Paths. I would use something like the below with your second Json example but, depends if you have arrays in your Json and partitioned collections, etc.
/prop/*
Index path for all paths under the specified label. Works with the following queries
SELECT FROM collection c WHERE c.prop = "value"
SELECT FROM collection c WHERE c.prop.subprop > 5
SELECT FROM collection c WHERE c.prop.subprop.nextprop = "value"
SELECT FROM collection c ORDER BY c.prop
/props/[]/subprop/?
/props/[]/subprop/?
Index path required to serve iteration and JOIN queries against arrays of objects like [{subprop: "a"}, {subprop: "b"}]:
SELECT tag FROM tag IN collection.props WHERE tag.subprop = "value"
SELECT tag FROM collection c JOIN tag IN c.props WHERE tag.subprop = "value"
这篇关于我的收藏的Azure Cosmos DB索引策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!