按属性过滤 orion 查询
Filtering orion queries by attributes
在 FIWARE Orion Context Broker 中过滤查询输出以使其仅包含具有特定属性的结果的最佳方法是什么?例如,假设有 5 个元素的属性名为 "A"、"B" 和 "C",另外 15 个元素只有 "A"(所有元素类型相同)。我只想收到前 5 个。在查询的属性字段中指定 ["A"、"B"、"C"] 似乎无助于过滤掉那些不符合条件的结果没有 "B" 和 "C"。
答案取决于考虑的 NGSI API 版本。
在 NGSIv1 中,通常(最后一段中描述了一个例外)您只能在 queryContext operation 的 attributes
字段中使用 "positive" 过滤器,即所有实体包括 A、B 或 C,但不包括包括 A 但不包括 B 或 C 的实体。
在 NGSIv2 中,您可以使用简单查询语言的以下功能(检查 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.
例如,要获取属性为 A 而不是 B 或 C 的所有实体,将使用以下内容:
GET /v2/entities?q=A;!B;!C
实际上,您也可以通过 String query filter.
在 NGSIv1 中使用 q
过滤器
在 FIWARE Orion Context Broker 中过滤查询输出以使其仅包含具有特定属性的结果的最佳方法是什么?例如,假设有 5 个元素的属性名为 "A"、"B" 和 "C",另外 15 个元素只有 "A"(所有元素类型相同)。我只想收到前 5 个。在查询的属性字段中指定 ["A"、"B"、"C"] 似乎无助于过滤掉那些不符合条件的结果没有 "B" 和 "C"。
答案取决于考虑的 NGSI API 版本。
在 NGSIv1 中,通常(最后一段中描述了一个例外)您只能在 queryContext operation 的 attributes
字段中使用 "positive" 过滤器,即所有实体包括 A、B 或 C,但不包括包括 A 但不包括 B 或 C 的实体。
在 NGSIv2 中,您可以使用简单查询语言的以下功能(检查 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.
例如,要获取属性为 A 而不是 B 或 C 的所有实体,将使用以下内容:
GET /v2/entities?q=A;!B;!C
实际上,您也可以通过 String query filter.
在 NGSIv1 中使用q
过滤器