With our latest Graphlytic 3.2. release we introduced a powerful feature - Query TemplatesThe main purpose of this significant improvement is to bring our vision to life and make Graphlytic the best place for all graph analysts, including those with a non-technical background.

What precisely do we mean by that? Our aim is to let Graphlytic users work efficiently with predefined Query Templates by easily selecting the requested template from the Global Repository and adding a variable range of parameters (depending on the complexity of the query). Use-case specific Query Templates from the simplest to the most complicated ones can be constructed by the administrators of Graphlytic application (or Graphlytic support on demand) and added to the Global Repository. The user can then simply select the template he or she wishes to apply for his analysis. Basics on how the Query Templates work were described in our previous blog post What's New in Graphlytic 3.2. Below, you will find a step-by-step tutorial on how to start with Query Templates, how to construct them, starting with the simple examples, gradually adding parameters to allow the users to set their own query criteria.

In this article, we'll present examples of Query Templates to give you an idea of how they can improve analysts' work and make it much more effective. All examples of Query Templates presented here will be applied to an IT infrastructure data set. You can try them by yourself in our IT Infrastructure Demo.

 

The main benefits of Query Templates

The answer is:

  • efficiency
    • by speeding up repetitive activities,
    • by giving a simple to use though powerful tool to analysts - users,
  • variability - the user can define parameters if the query allows it, e.g. set the maximal length of the path between two nodes to a defined level
  • and comfortable environment for analysts.

 

Exploring Options in Graphlytic

Analysts using graph visualization often need to:

  • Search for specific connections or patterns (with various depth and structure) to get insights from the analyzed data set.
  • Define the patterns to prevent something from happening or on the contrary to make something happen (e.g. as a part of the prevention procedures).
  • Find the shortest ways or dependencies between particular nodes.
  • Set queries to check the data sets for specific data on a repetitive base or almost on a regular basis.
  • Run certain queries as a part of enterprise reporting.
  • Prepare all of the above-mentioned points as soon as possible. 

The easiest way is to explore data sets manually in the 'Visualization page' by searching the data set, adding nodes and edges to the graph visualization, and examining their neighbors. This is the basic analysts' activity. No coding skills are required, and it can be very motivating to search for findings when new data sets are explored. On the other hand, it can be very time consuming if applied for repetitive tasks.  

For example, the analyst might want to find if there is any connection between the two nodes. In the 'Visualization page', he or she can select the nodes and click on the button "Find the shortest path". The shortest path is selected, displayed with the length (number of neighbors to get there) and the number of the paths with the same length. Every next search requests to repeat these steps.

Graph visualization - exploring the shortest path

The example of finding the shortest path when exploring data set in the 'Visualization page'.

 

Query Options in Graphlytic

The next level in traversing data sets is the work with the 'Search & Manage Data' screen. It is primarily designed for searching graph elements allowing the user to add discovered elements to an opened or new graph visualization. User permission rights set by the administrator define what data the user can access. Search for nodes on this screen is done using Search Queries. Taking into account the various skillsets of the users, Graphlytic gives the user three options for creating queries:

 

1.'Node Filter' Query

'Node Filter' Query, placed in the 'Query Bilder' panel (on the left, the active tab is set to 'Node Filter'). Queries are constructed using the fulltext search for nodes combined with the query builder. The user has the option to filter the nodes based on labels or property values. The user has to decide which labels or properties will be displayed in the result table. When the filter with selected values is set, the user hits the 'Run Query' button. Query results - the nodes found in the underlying graph database - are displayed in a table on the left side of the Search & Manage Data' screen. The table contains found nodes as rows, one per each node. The columns of the result table are the labels or properties preselected by the user in the previous step. The user can sort them. Finally, the user can select the nodes found by the Node Filter Query with three action options:

  • Visualize the query results in a new graph visualization - hitting the button 'Visualize'
  • Add the query results to an already opened graph visualization - hitting the button 'Add To Opened Visualization'
  • Export the query results (into CSV) - using the button 'CSV Export'

Node Filter in Graphlytic application. Two configuration items are filtered-out. Application_component8 and Rack20

'Node Filter' Query example of query filtering out the nodes with the label 'CI' (CI for 'Configuration Item') and the properties 'Application Component 8' and 'Rack 20'

 

2. 'Cypher' Query

'Cypher' Query, placed in the 'Query Bilder' panel (on the left, the active tab is set to 'Cypher') is so to say a twin option to the Node Filter Query for the users skilled in Cypher Query Language. Why the twin option? It allows using the same query constructed with the Node Filter Query but the query translated into the Cypher language (As you can see below, in the picture, running the Cypher statement in the 'Query Bilder panel' gives us the same results as introduced in point 1. Node Filter Query). Nevertheless, the user can construct any Cypher query and hit the 'Run Query' button. All consequent options are identical to the options described in detail in point 1.

Run Query screen with query for Application_component8 and Rack20

'Cypher Query' example of query filtering out the nodes with the label 'CI' (CI for 'Configuration Item') and the properties 'Application Component 8' and 'Rack 20' - identical query as in point 1. 'Node Filter' Query

 

3.Query Templates

Query Templates placed in the panel 'Add Search Queries From The Global Repository' (opened by clicking on the 'Add Query from Repository' button, on the top right of the 'Search & Manage Data' screen). Query Templates are the perfect solution for users who need to construct and run queries but have no programming skills. 

 

Managing Query Templates

Admins first! To set-up a new Query Template (and consequently any other Query Template) we'll need to go to the 'Application Menu' (top right on the screen) and select the 'Settings' option to get to the 'Settings' page:

Note: Please be aware that only the administrators or the users with permissions can see the 'Settings' option in the 'Application Menu'! 

 

Graphlytic: Settings page in the Application menu

On the left side of the screen, in the 'Application Settings' menu, click on the 'SEARCH_TABS' row.  The pane 'Update Setting SEARCH_TABS' will be displayed. 

Graphlytic: Update Setting for SEARCH_TABS

The configuration of the 'SEARCH_TABS' (and all the 'Application Settings' tabs as well) is entered in JSON format. When done, hit the 'Save' button. That's all for the admin part.

Note: You'll find examples of Query Templates in the chapters below.

 

Using Query Templates

Now, the user's turn. As mentioned before, the user can find all the Query Templates in the 'Search & Manage Data' screen by clicking on the 'Add Query from Repository' button. With one click on the empty checkbox, the user can pick the selected Query Template.

Graphlytic: Add Search Queries From The Global Repository

After hitting the button 'Add selected queries' the new tab will be added.

Graphlytic: Add selected queries button

The new tab could contain just the name of the Query Template and the 'Run Query' button (in case of the simplest queries); or it can contain few rows for adding parameters for the query. Query results - the nodes - are displayed in a table, identical to the table described in point 1.

 

In the following part, we'll introduce examples of how the admins or users with Cypher language programming skills (and permissions) can construct a specific Query Template. We'll start with just a simple Query Templates, step-by-step adding complexity to some of them. 

 

Query Templates Examples

We'll act as admins. Let's start with the simplest examples of Query Templates.  At this point, we don't intend to give the users the possibility to set their own criteria for the search. 

 

Example #1: Find all Service nodes.

Imagine that the user has a data set that is changing on a daily basis, and he or she needs to find all 'Service' nodes (i.e. nodes with the label 'Service') in the data set. In this case, we'll prepare a simple Query Template. The user can run the query with just one click. 

Admin:

A simple Cypher query for returning all nodes with the label 'Service' will sound like this: 

MATCH (a:Service) RETURN a

Now, the 'SEARCH_TABS' on the 'Settings' page, written in JSON format has to be modified to have this JSON string with Cypher query incorporated:

{
    "title":"Find all Service nodes",
    "template":{
        "textTemplate" : "",
        "cypherTemplate" : "MATCH (a:Service) RETURN a",
        "parameters" : []
    }
}

Note: Rules for modifying the JSON statements in 'SEARCH_TABS' are described in detail in the Graphlytic 'Administration manual', 'Search tab' section.

After clicking on the 'Save' button, the Query Template is ready for the user. 

User:

The user will go to the 'Search & Manage Data' screen, and select the 'Add Query from Repository' button. The user can simply pick the requested Query Template by clicking on the empty checkbox, like this:

Graphlytic: Query Template with the name Find all Service nodes

When the user confirms the 'Add selected queries' button, the new tab with the name 'Find all Service nodes' is added. To run the template, the user has to click on the 'Run Query' button: 

Graphlytic: Query Template Find all Service nodes  Run_Query Button

The results are displayed. In this case, with the prepared Query Template the user found 22 nodes:

Graphlytic: Query Template Results for Query Find_all_Service_nodes

After clicking on the 'Visualize' button, the user gets to the Visualization page, which contains visualized results - all 'Service' nodes - ready for further exploring:

Graphlytic: Query Template visualization for query Find_all_Service_nodes

 

Example #2: Find all Service nodes and all their related nodes (upgrade of Query Template from Example #1)

In this example, we'll develop the previous example of Query Template a bit, adding all related nodes to the graph visualization.

Admin:

The Cypher query will be like this now: 

MATCH (a:Service)-[r]-(b) RETURN a, r, b

The 'SEARCH_TABS' on the 'Settings' page, needs to be modified a bit:

{
    "title":"All Services and related nodes",
    "description":"Find all Service nodes and all their related nodes",
    "template":{
        "textTemplate" : "",
        "cypherTemplate" : "MATCH (a:Service)-[r]-(b) RETURN a, r, b",
        "parameters" : []
    }
}

 

User:

The user will again select the 'Add Query from Repository' button on the 'Search & Manage Data' screen and select the Query Template:

Graphlytic: Query Template Find_all_Service_nodes_and_all_related_nodes

After clicking on the 'Run Query' button, the results of the Query Template are displayed. As you can see, the query returned 172 elements now (of which 22 nodes of 'Service' nodes are the same, as in the previous example):

Graphlytic: Query Results for the query Find_all_Service_nodes_and_all_related_nodes

When the user clicks on the 'Visualize' button, the displayed graph visualization gets much more complex - showing all relevant nodes and relationships:

Graphlytic: Query Template visualization for the query Find_all_Service_nodes_and_all_related_nodes

 

Example #3: Find all Service nodes and all their related nodes in variable max depth, as param

This is a further upgrade of Query Template from Example #2 adding a parameter to the Query Template.

Now we'll step a bit further with the previous Query Template. We'll add a parameter, that'll give the user the variability - the option to set the maximal depth of relationships related to 'Service' nodes.

Admin:

The Cypher query gets bigger now: 

MATCH p=(a:Service)-[r*1..$depth]->(b) RETURN p

This is the updated 'SEARCH_TABS':

{
    "title":"All Services and related nodes (param)",
    "description":"Find all Service nodes and all their related nodes in variable max depth (as param)",
    "template":{
        "textTemplate" : "Return all Service nodes and related nodes with max depth $depth",
        "cypherTemplate" : "MATCH p=(a:Service)-[r*1..$depth]->(b) RETURN p",
        "parameters" : [
            {
                "parameter" : "depth",
                "type" : "NUMBER"
            }
        ]
    }
}

User:

The user will select the requested Query Template:

Graphlytic: Query Template with parms Find_all_Service_nodes_and_all_related_nodes

The user can now define the maximal dept for related nodes to the 'Service' nodes, without limitation. Let' say, we want to find all related nodes to the depth of 3. As you can see, there is a blank space, where the user sets the depth number (we already entered number 3). When the user clicks on the button 'Run Query' the Query Results will bring 238 nodes and 275 relationships:

Graphlytic: Result of Query Template with param Find_all_Service_nodes_and_all_related_nodes

The graph visualization is now of much higher complexity:

Graphyltic: Graph visualization of Query Template with param Find_all_Service_nodes_and_all_related_nodes

 

Example #4: Find all nodes in variable depth starting from the chosen 'Service' node

This is a further upgrade of the Query Template from Example #3 with two parameters in the Query Template.

This example allows the user to decide which 'Service' nodes will be displayed (not all), and set the maximal dept for related nodes. 

Details on how to set up this Query Template are described in detail in this post: What's New in Graphlytic 3.2 Enjoy!

And last, but not least:

 

Example #5: Find the shortest path between two nodes

The Template Query for finding the shortest path contains two parameters as well. The user can use any two nodes from the data set for his or her query. 

Admin:

This is the Cypher query: 

MATCH p=shortestPath((a:CI)-[*]-(b:CI)) WHERE a.name='$CI1' AND b.name='$CI2' RETURN p

The admin will add to the 'SEARCH_TABS' the following JSON:

{
    "title":"Find the shortest path",
    "description":"Find the shortest path between two nodes",
    "template":{
        "textTemplate" : "Find the shortest path between $CI1 and $CI2",
        "cypherTemplate" : "MATCH p=shortestPath((a:CI)-[*]-(b:CI)) WHERE a.name='$CI1' AND b.name='$CI2' RETURN p",
        "parameters" : [
            {
                "parameter" : "CI1",
                "type" : "NODE_PROPERTY_VALUES",
                "config" : {
                    "multiple" : false,
                    "property" : "name",
                    "labels" : ["CI"],
                    "placeholder" : "configuration item"}
            },
            {
                "parameter" : "CI2",
                "type" : "NODE_PROPERTY_VALUES",
                "config" : {
                    "multiple" : false,
                    "property" : "name",
                    "labels" : ["CI"],
                    "placeholder" : "configuration item"
                }
            }
        ]
    }
}

User:

'Find the shortest path' Query Template will be selected by the user:

Graphlytic: Query Template Find_the_shortest_path

As we can see, the user has the free choice for choosing two of any configuration items (nodes) from the data set:

Graphlytic: Run Query Template Find_the_shortest_path

Now, we can return to the beginning of this article where we introduced the exploring options. We were looking for the shortest path between 'Virtual Manager 54' and 'Database 86'. We can enter the same endpoints to our new Query Template, to find if there are more options; or if there are more nodes with the same properties. The result is that there is the same path (no other paths or components with the same properties in the data set):

Graphlytic: Query Template results Find_the_shortest_path

 

Graphlytic: Graph visualization of Query Template Find_the_shortest_path

Feel free to try out all the examples of Query Templates in our online IT Infrastructure Demo. Leave us your comments with your ideas and experience with the Quer Templates below.

If you'd like to set up your own Query Templates you can do it in several ways in our free Graphlytic options: