Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter by attribute value in Orion Context Broker 0.23.0

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 currently executing GET operations as indicated in http://telefonicaid.github.io/fiware-orion/api/v2/ and what I obtain is the whole set of entities, no filtering action. Could you please help me in this regard with a clear example on how to use the new REST API, NGSI v2?

Thank you very much in advance

like image 695
juanba1984 Avatar asked Oct 20 '22 05:10

juanba1984


1 Answers

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.

like image 115
fgalan Avatar answered Jan 04 '23 05:01

fgalan