【问题标题】:Azure Cosmos DB partitioning and Indexing of Data in SQL API using PATH使用 PATH 对 SQL API 中的数据进行 Azure Cosmos DB 分区和索引
【发布时间】:2019-04-10 15:19:00
【问题描述】:

我正在将 IoT 数据收集到 Azure cosmos DB。我知道 COSOMOS DB SQL API 是由 Path 自动索引的。我在每个文档中大约有 150 个传感器,大多数 sql 查询都是

DeviceId 已经是分区键

选择 c.sensorVariable From c where c.DeviceId = 'dev1' AND c.time= date1'

{ "DeviceId" : 'dev1' , "time" : 123333 , "sensor1" : 20 , "sensor2" : 40}

我将获取各种传感器数据,但我所有的查询都取决于 deviceId 和 time(在 Unix Timestamp 中)

是否可以对 deviceID 和 time 上的数据进行索引,并排除也在同一路径 / 中的其他键。

并且默认用于收集

"includedPaths": [
    {
        "path": "/*",
        "indexes": [
            {
                "kind": "Range",
                "dataType": "Number",
                "precision": -1
            },
            {
                "kind": "Range",
                "dataType": "String",
                "precision": -1
            },
            {
                "kind": "Spatial",
                "dataType": "Point"
            }
        ]
    }
],

我觉得 DataType String 不应该是 Hash 类型的索引而不是 Range 吗?这个精度是多少:-1

在 Azure cosmos DB 文档示例中,我看到字符串的精度为 3,我不明白为什么?

如果我有 100 台设备并且每秒钟放置一次数据,那么哪种类型的索引更好?

【问题讨论】:

  • 您好,我的回答对您有帮助吗?
  • 部分是杰,但它有助于获得知识

标签: azure azure-cosmosdb azure-cosmosdb-sqlapi


【解决方案1】:

是否可以对 deviceID 和 time 上的数据进行索引并排除其他 键,它们也在同一路径中

是的。您可以通过IncludedPathsExcludedPaths 自定义索引策略。

如:

var excluded = new DocumentCollection { Id = "excludedPathCollection" };
excluded.IndexingPolicy.IncludedPaths.Add(new IncludedPath { Path = "/*" });
excluded.IndexingPolicy.ExcludedPaths.Add(new ExcludedPath { Path = "/nonIndexedContent/*" });

await client.CreateDocumentCollectionAsync(UriFactory.CreateDatabaseUri("db"), excluded);

更多详情请参考here

这个精度是多少:-1

在 Azure cosmos DB 文档示例中,我看到字符串的精度为 3,我不明白为什么?

基于Index data types, kinds, and precisions

对于哈希索引,字符串和数字的值都在 1 到 8 之间。默认值为 3。对于 Range 索引,该值可以是 -1(最大精度)。对于字符串或数字值,它可以在 1 到 100(最大精度)之间变化。

您可以关注此statement 做出选择。

如果我有 100 台设备,并且每秒钟放置一次数据是什么类型的 索引更好?

很难说哪种索引模式是最佳选择。它应该与一致性级别和您对读写性能的要求一起考虑。你可以参考这个paragraph

【讨论】:

  • 感谢您的回复。我观察到的另一件事是 { "datapoint1" : 23 , "datapoint2" : 20 , "datapoint3" : 45 } 就像我有 150 个传感器 { "keyDataPoint" : 22 , "Data" : { "datapoin1" , "datapoint2" 。 ... } } 如果我将数据保持在上述格式并将数据索引到一个级别,那将提高性能。
  • @AmjathKhan 谢谢你的分享。那么,还有什么问题吗?
  • 我将按照我的分享进行测试。谢谢你,你对我帮助很大。
  • @AmjathKhan 嗨,现在有什么进展吗?我的回答对你有帮助吗?
猜你喜欢
  • 2018-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-03
  • 2018-09-02
  • 1970-01-01
  • 1970-01-01
  • 2023-02-21
相关资源
最近更新 更多