在 Orion Context Broker 0.23.0 中按属性值过滤

Filter by attribute value in Orion Context Broker 0.23.0

在当前版本的 Orion Context Broker 0.23.0 中,新增功能之一是它支持根据属性值过滤实体 (NGSI v2)。我目前正在执行 http://telefonicaid.github.io/fiware-orion/api/v2/ 中指示的 GET 操作,我获得的是整个实体集,没有过滤操作。在这方面,您能否通过一个关于如何使用新 REST API、NGSI v2 的清晰示例来帮助我?

非常感谢您

NGSIv2 过滤功能基于以下操作:

GET /v2/entities?q=<query_string>

其中 query_string 指定在 NGSIv2 specification document 中定义的查询字符串。例如,要获取 temperature 小于 24、humidity 在 75 到 90 之间以及 status 为 "running" 的所有实体,请使用以下操作:

GET /v2/entities?q=temperature<24;humidity==75..90;status=running

您还可以使用 "traditional" NGSIv1 进行查询,使用 POST /v1/queryContext 负载中的 scope 字段。同样的查询将通过以下方式完成:

 POST /v1/queryContext

 {
  "entities": [
      {
      "type": "",
      "isPattern": "true",
      "id": ".*"
      }
  ],
  "restriction": {
      "scopes": [
        {
          "type": "FIWARE::StringQuery",
          "value": "q=temperature<24;humidity==75..90;status=running"
        }
      ]
    }
 }

following link 提供了额外的信息。

请注意,某些过滤器(例如 greater/less than、ranges 等)假定属性值本机类型是数字。考虑到 NGISv1 对 create/update 属性的操作总是将值转换为字符串(由于 XML 兼容性,在 NGSIv2 中不再保留)。因此,如果您需要将属性值存储为数字以应用 greater/less 比、范围等过滤器,然后使用 NGSIv2 操作来 create/update 这些属性。 the following piece of documentation.

中更详细地解释了警告