Fiware Orion:订阅表达式中的布尔值使用问题
Hey there! Let's tackle your questions about Fiware Orion's subscription query expression system one by one—this stuff can be tricky at first, so I'll break it down clearly:
1. Does the expression language support boolean values?
Absolutely, but with specific use cases tied to entity attributes. Orion's NGSIv2-based query language lets you match boolean-type attributes directly. For example, if you have an entity with a boolean property like isOperational, you can use queries like "q":"isOperational==true" or "q":"isOperational==false" to target those entities. Just remember to use lowercase true/false—uppercase variants will be treated as string literals and won't match boolean fields correctly.
2. Can I use "q":true to match all events?
Nope, that won't work. The q parameter is designed to accept attribute-based match conditions following strict NGSIv2 syntax. Passing a raw true isn't a valid query, and Orion will treat it as an invalid condition (likely returning no matches).
If you want to match all events, you have two simple options:
- Omit the
qparameter entirely: Orion defaults to matching all entity changes (or all changes for a specifictypeif you've specified one). - Use a valid always-true expression (more on that in the next section).
3. Why did "q":1==1 fail?
Two key issues here:
First, 1==1 isn't a valid Orion query structure. The q parameter requires conditions to follow the pattern [attributeName][operator][value]—standalone boolean expressions like 1==1 aren't recognized.
Second, in JSON configuration, the q value must be a string. Writing "q":1==1 is actually invalid JSON syntax (since 1==1 isn't a valid JSON primitive), so Orion won't even parse it correctly.
If you need an explicit always-true condition to match all events, use one of these valid string-based expressions:
"q":"id!=null": Every entity has anidattribute, so this condition will always evaluate to true."q":"_exists_=*": This checks for entities that have at least one attribute (which all valid entities do), effectively matching everything.
内容的提问来源于stack exchange,提问作者cdupont

