Filter by attribute value in Orion Context Broker 0.23.0

In the current version of Orion Context Broker, 0.23.0, one of the new features added is that it supports filtering objects according to attribute values ​​(NGSI v2). I am currently performing GET operations as specified in http://telefonicaid.imtqy.com/fiware-orion/api/v2/ and I get the whole set of objects, no filtering actions. Could you help me in this regard with a clear example of how to use the new REST API, NGSI v2?

Thank you in advance

+5
source share
1 answer

NGSIv2 filtering capabilities are based on the following operation:

GET /v2/entities?q=<query_string> 

where query_string indicates the query string defined in the NGSIv2 specification document . For example, to get all objects for which temperature less than 24, which humidity is in the range from 75 to 90 and which status "works", uses the following operation:

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

You can also make queries using the "traditional" NGSIv1, using the scope field in the POST /v1/queryContext . The same request will be executed as follows:

  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 contains additional information.

Note that some filters (e.g., large / smaller, ranges, etc.) assume that the attribute's native value type is a number. Note that NGISv1 operations for creating / updating attributes always convert values ​​to strings (due to XML compilation no longer supported by NGSIv2). Thus, if you need to save attribute values ​​as a number in order to apply filters of larger or smaller sizes, ranges, etc., Then use NGSIv2 operations to create / update these attributes. The disclaimer is described in more detail in the following piece of documentation .

+3
source

All Articles