Merging Nodes in Search
While it is possible to search and retrieve a filtered part of the graph, it is sometimes helpful to retrieve structural graph data as part of the node.
This approach merges multiple nodes in a graph into one node. This combined node can simplify processing the node.
The nested search is executed for every node in the result. The result of the nested search is then merged with the original node data.
Most cloud resources are maintained in an account. Accounts are modeled as nodes in Fix Inventory.
Resources reference the region node, while the region node references the account node. In order to retrieve the account, the graph has to be traversed inbound from the resource node until the account node is found. While this is possible, it might be more convenient to get the account information as part of the node!
In this example, we search for nodes of kind volume
. For every element that is returned, a nested search is executed, which will traverse the graph inbound until it finds a node of kind account
.
> search is(volume) { account: <-[0:]- is(account) } limit 1 | dump
reported:
.
.
account:
reported:
.
.
The result of this nested search is merged with the volume node on root level under the name account.
The complete information about the account is then available as part of the volume node:
You will notice that the account, cloud, region, and zone are displayed for every resource. This data is available in the /ancestors
node section.
A nested search is a complete, standalone query and can use the features of any other search.
The result of a nested search is merged with the original node under the given merge name.
If the merge name is a simple literal, zero or one result of the nested search is expected. This also means, that the graph traversal of the nested search stops, when the first matching element is found.
If the expected result of the nested search is a list, than the merge name has to be defined with square brackets.
The following search will traverse inbound on every element and collect all predecessors under the name predecessors
). Please note the square brackets in the name predecessors[]
- which will tell the search engine to return all predecessors, not only the first one. As a result the node is returned with a new property, which contains the list of all predecessors.
> search is(volume) { predecessors[]: <-- all } limit 1 | dump
reported: