Alex Glikson
Alex Glikson

Reputation: 441

Filtering orion queries by attributes

What is the best way to filter the output of a query in FIWARE Orion Context Broker so that it includes only results with certain attribute? For example, assume that there are 5 elements with attributes named "A", "B" and "C", and another 15 only with "A" (all share the same element type). I want to receive back only the former 5. Specifying ["A", "B", "C"] in attributes field of the query doesn't seem to help with filtering out those results that don't have "B" and "C".

Upvotes: 2

Views: 437

Answers (1)

fgalan
fgalan

Reputation: 12294

The answer depends on the NGSI API version taken into account.

In NGSIv1, typically (there is one exception described in the last paragraph) you can only use "positive" filters in the attributes field in queryContext operation, i.e. all the entities that includes A, B, or C, but not the entities that include A, but not B or C.

In NGSIv2, you can use the following feature of the simple query language (check NGSIv2 specification):

Unary negatory statements use the unary operator !, while affirmative unary statements use no operator at all. The unary statements are used to check for attribute existence. E.g. temperature matches entities that have an attribute called 'temperature' (no matter its value), while !temperature matches entities that do not have a temperature attribute.

For example, to get all the entities with attribute A but not B or C the following will be used:

GET /v2/entities?q=A;!B;!C

Actually, you can use q filters also in NGSIv1 through the means of the String query filter.

Upvotes: 1

Related Questions