Filter by attribute value in Orion Context Broker 0.23.0

前端 未结 1 614
陌清茗
陌清茗 2021-01-18 18:42

In current version of Orion Context Broker, 0.23.0, one of the new added features is that it supports filtering entities according to attribute values (NGSI v2). I am curren

相关标签:
1条回答
  • 2021-01-18 19:03

    The NGSIv2 filtering capabilities are based in the following operation:

    GET /v2/entities?q=<query_string>
    

    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
    

    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"
            }
          ]
        }
     }
    

    The following link provides additional information.

    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.

    0 讨论(0)
提交回复
热议问题