Key expressions
The WHERE, ORDER BY and SHOW clauses often use simple attribute names, as in the examples describes in the using query language section. In some cases, however, a query needs more complex specifications.
The first option is to use a 'key expression' to retrieve information from related nodes. Key expressions start with a # character.
The key expression formats are:
#role:rel:role:kind.attr | Traverses from the node via the roles and relationships, returning the attribute of the target node. If more than one target can be reached, returns a list of up to 10 (or an alternative limit chosen in the system options). |
#role:rel:role:kind | As explained in the previous row, but returns a 'NodeHandle' for the target node, rather than an attribute of it, useful as a function argument. |
#role:rel.attr | Step in to a relationship and get its attribute. |
#role:rel | Step in to a relationship and return a 'RelationshipHandle' for it, to pass into functions. |
#:role:kind.attr | Step out of a relationship and get the destination node's attribute. |
#:role:kind | Step out of a relationship and return the destination 'NodeHandle'. |
#id | Return the node's id in hex string format. |
#partition | Returns the node's datastore partition id. |
## | Returns the node ID in binary format. |
# | Returns a 'NodeHandle' for the node itself, to pass into various functions. |
#node | Returns the node itself. |
#"<fmt>"(a,b,c) | Applies Python format string to the attributes (which can be key expressions) in the list. |
So, extending the example of finding Windows hosts, this expression shows the IP addresses of the hosts' network interfaces:
#DeviceWithInterface:DeviceInterface:InterfaceOfDevice:NetworkInterface.ip_addr
The traversal syntax permits components to be wild-carded by leaving them blank. For example, the following query shows the names of all software running on a Host, both Business Application Instances and Software Instances:
Key expression name binding
Repeated key expressions can lead to long impenetrable search expressions. To avoid this, they can be bound to names. For example:
WITH #Host:HostedSoftware:RunningSoftware:SoftwareInstance AS si
SHOW name, EXPLODE si.type, si.version, si.count