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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With