Help Center> Graph Engine Service> Getting Started> Querying and Analyzing a Graph
Updated on 2022-09-14 GMT+08:00

Querying and Analyzing a Graph

This following content describes how to query a graph.

Accessing a Customized Graph

You can query and analyze graphs in any of the following ways if a graph is created without using any template:
  • Gremlin commands
    1. Enter the query command in the Gremlin text box in the lower part of the page, for example, g.V().limit(100).

      It may take a long time for the system to return a large amount of data. You are advised to add the limit parameter and set it to less than 1,000.

      Figure 1 Gremlin query
    2. Press Enter to run the Gremlin command. The query result is displayed in both the canvas and result pane.
      Figure 2 Gremlin query result
  • Cypher commands
    1. Enter the query command in the Cypher text box in the lower part of the page, for example, match (n) return n limit 100.
      Figure 3 Cypher query
      • If this is your first time using Cypher, click Create Index in the result pane. You do not need to perform this operation in subsequent operations.
      • match (n) return n limit 100 queries details about 100 vertices.
    2. Press Enter to run the Cypher command. The query results are displayed in both the canvas and result pane.
      Figure 4 Query result
  • Algorithm analysis
    1. Available algorithms are displayed in the left pane of the graph editor. Select the analysis algorithm you want to use.
      Figure 5 Algorithm list
    2. Expand the algorithm by clicking and configure the parameters as required. Take PageRank as an example. alpha indicates the weight coefficient, and its value is 0.85. convergence is the convergence coefficient, and its value is 0.00001. max_iterations indicates the maximum iterations and its value is 1,000. directed indicates whether to consider the edge direction and the default value is true.
      Figure 6 Setting PageRank algorithm parameters
    3. Click to execute the algorithm. The analysis result is displayed in both the canvas and result pane.
      Figure 7 Analysis results

Accessing a Graph Created Using a Template

In addition to queries using Gremlin commands, Cypher commands, and algorithms, the following queries are also available for a graph created using an industry-specific template:
  • Asset Management Graph Template
    Query 1: List administrators and their applications.
    • Command: g.V().hasLabel('admin').outE().otherV().hasLabel('application').path()
    • Procedure: Click the run button. The query result is displayed in the graph on the canvas.
    Query 2: Find all paths from administrator x to equipment room x.
    • Principle: get${Administrator x} is the source vertex and ${Equipment room x} is the target vertex. Find out all paths using the n-Paths algorithm, where source is Administrator x, target is Equipment room x, direct is false, n is 10, and k is 10.
    • Procedure: Click the run button. In the dialog box that is displayed, select administrator x and equipment room x from the drop-down list box. After the operation is complete, the graph is displayed on the canvas.
    Query 3: Find all VMs and physical machines on which application x depends.
    • Principle: get${Application x} is the input to find all points at layer 2. Use the K-Hop algorithm, where k is 2, source is x, and mode is in.
    • Procedure: Click the run button. In the dialog box that is displayed, set the application x (select the application from the drop-down list box and drag the vertex of the application entity to the drop-down list box). After the operation is complete, the graph is displayed on the canvas.
    Query 4: Find all vertices with a specified label, for example, all administrators, equipment rooms, and physical machines in the graph.
    • Principle: Search vertices by label.
    • Procedure: Click the run button. In the dialog box that is displayed, select label from the drop-down list box. The query result is displayed in the graph on the canvas.
  • Power Distribution Management Template

    Query 1: Query the power supply range.

    • The sub-queries are as follows:
      1. Locate power substation busbars.
      2. Query the power supply scope of a busbar.
      3. Query user points within the power supply scope of a busbar.
    • Procedure: Click the run button. In the dialog box that is displayed, select the busbar value. The query result is displayed in the graph on the canvas.

    Query 2: Analyze the outage fault.

    • The sub-queries are as follows:
      1. Trace back the faulty point from the power-off user point.
      2. Query faulty point details.
    • Procedure: Click the run button. In the dialog box that is displayed, select parameters of the faulty point or the power-off user point. The query result is displayed in the graph on the canvas.

    Query 3: Query the ring circuit power supply.

    • The sub-queries are as follows:
      1. Locate the ring circuit supply line.
      2. Locate contact switches in the ring circuit supply line.
    • Procedure: Click the run button. The query result is displayed in the graph on the canvas.

Viewing the Analysis Result

You can view the running record and query result in the result pane or click the Export button on the right to download the analysis result.

Figure 8 Execution result