在 cumulocity API 中使用 "revert" 参数时的奇怪行为

Strange behaviour when using "revert" parameter in cumulocity API

当使用 REST API 获取测量值时,我可以传递 revert 参数来反转测量值的顺序:

https://tenant.cumulocity.com/measurement/measurements?revert=true

但是,一旦我将一个额外的设备作为参数传递,

https://tenant.cumulocity.com/measurement/measurements?revert=true&source=876123

revert 关键字似乎停止工作。显示的第一个值有时比实际最新值早一天。事实上,当指定 revert=false 或省略该参数时,第一个显示的值的时间戳实际上按时间顺序在第一个显示 revert=true 的值的时间戳之后。

是否对此有任何解释,或者指定来源时 revert 关键字无效?

完整理解:

  • 当有人查询我们的数据库时,我们得到正确的索引,return根据这个索引得到结果(性能原因);根据查询参数选择索引,

  • 参数'revert'作用于这个索引,确切的意思是return导致恢复到索引顺序

为什么在你的情况下你会得到错误的结果:

First Item with no source specified and revert=true ...

我们得到 'natural' 索引(将文档添加到数据库的顺序),并且 return 元素的顺序恢复为添加顺序。顺序或添加与时间顺序的匹配是偶然的

First Item with source specified ...

在这种情况下,我们得到索引 'bySource' 这是 'source' 属性 上的 b 树,将仅按 'source' 排序;在这种情况下,数据未按 'time'

排序

如果您想要通过特定 'source' 获得结果并通过 'time' 排序,您必须强制应用程序使用按 SourceAndTime 索引:) 以及如何做到这一点,请简单地使用这个 URL:

https://tenant.cumulocity.com/measurement/measurements?dateTo=2015-12-22&dateFrom=1970-01-01&source=10307&revert=false

在这种情况下,应用程序通过 SourceAndByTime 获取索引并且索引具有按源和时间排序的数据,当您添加 revert = true 时,结果将恢复为时间顺序。

此致,
阿卡迪乌斯