5

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

fgalan
  • 11,732
  • 9
  • 46
  • 89
juanba1984
  • 357
  • 2
  • 13

1 Answers1

3

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.

fgalan
  • 11,732
  • 9
  • 46
  • 89
  • 1
    That functionality will be available in Orion 0.24.0 (expected release date: early September 2015). However, the functionality is already implemented in the develop branch in the Orion repository at https://github.com/telefonicaid/fiware-orion if you are in a hurry and need it right now. – fgalan Aug 12 '15 at 17:47
  • Is it possible to use these restrictions also for subscriptions ? I would like to use geolocalisation restriction on subscription. If yes, i'm going update orion to the lastest version. :) – Xavier Aug 14 '15 at 11:44
  • By the moment (develop branch now and Orion 0.24.0 soon) the filtering capabibilties work for queries. However, we are planning also to include them for subscriptions in a future version. Have a look to the current NGSIv2 draft specification ("Context Subscriptions " section) for details: http://telefonicaid.github.io/fiware-orion/api/v2/ – fgalan Aug 14 '15 at 21:13
  • I'm following the link you mentionned already but I'm always getting "All entites" like if filters where not doing anything. http://192.168.1.3:1026/v2/entities?q=BatteryVoltage<3400 http://192.168.1.3:1026/v2/entities?q=type=TinyNodeSensor http://192.168.1.3:1026/v2/entities?type=TinyNodeSensor i tryed many many combinations of "q=..." or followed the NGSI V2 Cookbook but i always get "All the entities saved in Orion" what could have been wrong ? - the way i created entities (with V1) - the upgrade ? (i assume that if orion respond to .../v2/entities; is is installed correctly) – Xavier Aug 23 '15 at 09:31
  • Note that `GET /v2/entities` was developed in 0.23.0 (released on early July 2015) but that `q=` filters will be included in 0.24.0 (which, as I explain in a previous comment, is to be release soon, probably in early/mid September). Thus, at the present moment, the above operations will only work if the Orion version instaled in you 192.168.1.3 has been compiled and installed from sources. Is that the case? – fgalan Aug 25 '15 at 18:34