Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Basic Operations and Compatibility

Updated on 2024-12-03 GMT+08:00

Basic Operations

Operation

Cypher Statement

Querying vertices

match (n) return n

Querying edges

match (n)-[r]->(m) return n, r, m

Querying paths

match (n:user)-[r]->(m:movie)-->(s:series) return n,r,m,s

Querying information by specifying filtering criteria

match(n:user) where n.userid>=5 return n

Grouping and aggregating

match(n:movie) return n.genres, count(*)

Deduplicating

match(n:movie) return distinct n.genres

Sorting

match(n:movie) return n order by n.movieid

Creating a vertex

create (n:user{userid:1}) return n

Creating an edge

match (n:user{userid:15}),(m:movie{movieid:10}) create (n)-[r:rate]->(m)

Deleting a vertex

match (n:user{userid:1}) delete n

Modifying labels

match (n:user{userid:1}) set n:movie return n

Modifying properties

match (n:user{userid:1}) set n.userid=2 return n

Compatibility to Cypher

  1. Cypher clauses

    Cypher implements a couple of clauses. You can combine clauses to implement different query semantics, including vertex and edge filtering, multi-hop query, sorting and deduplication, and grouping and aggregation.

    Currently, GES supports the Cypher clauses listed in the following table.

    Table 1 Supported Cypher clauses

    Clause

    Support

    Example

    match

    Partially supported

    match (n:movie) return n

    optional match

    Partially supported

    optional match (n)-->(m) where id(n)='1' return m

    return

    Supported

    return [1,2,3] as p

    with

    Supported

    match (n) with labels(n) as label, count(*) as count

    where count > 10 return *

    where

    Supported

    match (n:movie) where n.movieid > 10 return n

    order by

    Supported

    match (n:movie) return n order by n.genres

    skip

    Supported

    match (n:movie) return n order by n.genres skip 5

    limit

    Supported

    match (n:movie) return n order by n.genres skip 5 limit 10

    create

    Supported

    create (n:user{_ID_: 'Jack' }) return n

    delete

    Supported

    match (n:movie)<-[r]-(m:user) delete r

    set

    Supported

    match (n:user{userid:0}) set n.gender='M' return n

    call procedures

    Supported

    call db.schema()

    unwind

    Supported

    unwind [1, 2, 3] as p return p

    union

    Supported

    match (n:movie) return id(n) union match (n:user) return id(n)

    NOTE:

    Union is available for graphs smaller than 10 billion edges only.

    NOTE:
    1. Currently, merge and foreach operations are not supported. Cypher statements cannot add or delete indexes.
    2. GES metadata is not schema-free, and the vertex and edge label properties are strictly restricted. Therefore, the remove operation is not supported.
    3. The order by clause does not support sorting of the list type. When Cardinality of the property value is not single, the sorting result is unknown.
    • Available items for the match clause

      Item

      Description

      Example Clauses

      Earliest Version Required

      Vertex pattern

      Patterns for matching vertex with specified labels, properties, and IDs.

      match (n:movie{title:'hello'})

      match (n) where id(n)='xx'

      2.2.16

      Edge pattern

      Patterns for matching directional and non-directional edges with specified labels and properties. Specified IDs of both start and end vertices are supported.

      match (n)-[r] -> (m)

      match (n)-[r]- (m)

      match (n)-[r:rate{Rating:1}] - (m)

      match (n)-[r]- (m) where id(n)='x'and id(m)='y'

      2.2.16

      Path

      Anonymous paths

      match (n)-[r]->(m)-->(s)

      2.2.16

      Named paths

      match p=(n)-[r]->(m)-->(s)

      2.2.19

      Multiple patterns

      You can enter multiple patterns following match and separate them with commas (,).

      match (n)-[r]->(m), (m)-->(s)

      2.2.16

      Multi-match

      You can enter multiple match clauses. You can use with to connect multiple clauses.

      match (n)-[r]->(m) with m match (m)-->(s)

      2.2.16

      Variable-length path pattern

      Patterns for matching variable-length paths starting with a specified vertex.

      match p=(n)-[r*1..3]->(m) where id(n)='xx'return p

      match p=(n{title:'name'})-[r*1..3]->(m) return p

      2.2.19

      Traversal conditions for matching variable-length paths.

      match p=(n)-[r*1..3]->(m) where id(n)='xx'and all (x in nodes(p) where x.prop='value1') return p

      2.2.28

      Both start vertex and end vertex of a variable-length path can be specified.

      match p=(n)-[r*1..3]->(m) where id(n)='xx' and id(m)='y' return p

      2.3.9

      Deduplication by end vertex is supported:

      match p=(n)-[r*1..3]->(m) where id(n)='xx' return distinct m

      2.3.17

  2. Parameterized queries

    Cypher supports parameterized queries. Numeric and string values in a query statement are extracted and converted to parameters for faster compilation, improving the query speed.

    There are some examples of parameterized queries:

    • Example 1
      POST http://{SERVER_URL}/ges/v1.0/{project_id}/graphs/{graph_name}/action?action_id=execute-cypher-query
      {
               "statements": [{
                         "statement": " match (n:user) where n.occupation = $occupation return n",
                         "parameters": {
                               "occupation" : "artist"
                          },
                         "resultDataContents": ["row"]
               }]
      }
    • Example 2
      POST http://{SERVER_URL}/ges/v1.0/{project_id}/graphs/{graph_name}/action?action_id=execute-cypher-query
      {
               "statements": [{
                         "statement": " match (n:user {`Zip-code`:'98133'}) set n = $props return n",
                         "parameters": {
                                 "props": {
                                 "gender": "M",
                                 "age": "56+"
                              }
                          },
                         "resultDataContents": ["row"]
               }]
      }
    NOTE:

    There are some scenarios where parameterized queries are not supported. The following syntax is not valid:

    1. Using $param to search by property key and value. For example, match (n) where n.$param = 'something'
    2. Using $code for vertex and edge labels. For example, match (n:user) set n:$code
  3. Supported data types

    Currently, GES supports 10 data types: char, char_array, float, double, Boolean, long, Integer, date, enum, and string. Both Boolean and numeric types are supported in the Cypher syntax. The following table lists the mapping between other types and Cypher data types.

    Table 2 Mapping between data types of GES and Cypher

    GES

    Cypher

    Description

    char

    String

    -

    char_array

    String

    -

    string

    String

    -

    enum

    String

    The Cypher syntax does not provide enum-related syntax. During Cypher query, an enum is converted to a string. When Cypher is used to set properties, values that are not in the enumeration list fail to be set.

    date

    Temporal

    Currently, Cypher dates can be converted into GES dates, but Cypher date functions cannot be used for inputting a date.

    Table 3 Special types supported by Cypher

    Type

    Supported

    Example

    Node

    Yes

    match (n) return n limit 10

    Relationship

    Yes

    match (n)-[r]->(m) return r limit 10

    List

    Yes

    return [1,2,3] as li

    Map

    Yes

    match (n)-->(m) return {start:id(n), end:id(m)}

    Path

    Yes

    match p=(n1)-[:friends*1..2]-(n2) return p limit 10

    Point, Spatial

    No

    -

    NOTE:

    For the special types listed above, only the List type can be used to match multi-value properties in GES. Other types cannot be used in a set statement for setting the value of a property.

  4. Vertex ID compatibility
    • Cypher does not provide the syntax for setting the ID when a vertex is added. In GES, however, an ID of the string type is required to uniquely identify a vertex. To use the Cypher syntax in GES, add _ID_ to specify the ID of a vertex in the create statement. For example, the create(n{_ID_:'123456'}) statement creates a vertex whose ID is 123456.
    • If the ID is not specified, a random ID is generated for the vertex.
      NOTE:

      The _ID_ identifier is supported only in the create statement. The match and set clauses do not support the _ID_ identifier. In the match clause, you can use the id() function to obtain the vertex ID.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback