且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-26 13:57:58

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

The NGSIv2 filtering capabilities are based in the following operation:

GET /v2/entities?q=<query_string>

其中query_string指定 NGSIv2规范文档中定义的查询字符串一个>.例如,要获取所有temperature小于24,humidity在75到90之间且status在运行"中的实体,请使用以下操作:

where query_string specifies the query string as defined in the NGSIv2 specification document. For example, to get all the entities which temperature is less than 24, which humidity is in the range between 75 and 90 and which status is "running" use the following operation:

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

您还可以使用POST /v1/queryContext有效负载中的scope字段,使用传统" NGSIv1进行查询.相同的查询将通过以下方式进行:

You can also do queries using "traditional" NGSIv1, using the scope field in the POST /v1/queryContext payload. The same query will be done in the following way:

 POST /v1/queryContext

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

以下链接提供了其他信息.

请注意,某些过滤器(例如大于/小于范围等)假定属性值本机类型是数字.考虑到创建/更新属性的NGISv1操作总是将值转换为字符串(由于XML的兼容性,不再由NGSIv2维护).因此,如果您需要将属性值存储为数字以应用大于/小于范围等过滤器,则可以使用NGSIv2操作来创建/更新这些属性. 以下文档中对此警告进行了详细说明 a>.

Note that some filters (e.g. greater/less than, ranges, etc.) assume that the attribute value native type is a number. Take into account that NGISv1 operations to create/update attributes always transform the values to strings (due to XML compability, no longer mantained in NGSIv2). Thus, if you need to store attribute values as number to apply greater/less than, ranges, etc. filters, then use NGSIv2 operations to create/update these attributes. The caveat is explained in more detail in the following piece of documentation.