HugeGraph Cypher
Overview
HugeGraph supports Cypher, the declarative graph query language originally created by Neo4j and standardized as
openCypher. While Gremlin is an imperative traversal language, Cypher lets you describe the graph pattern you want
(MATCH, WHERE, RETURN) and lets the engine decide how to execute it.
HugeGraph supports the openCypher 9 syntax subset, parsing declarative pattern queries directly and bridging them seamlessly to the underlying TinkerPop graph traversal engine. For complete coverage and boundaries, see Cypher Compatibility.
When to use Cypher vs Gremlin
| Use Cypher when | Use Gremlin when |
|---|---|
| You are migrating from Neo4j or already know Cypher | You need the full HugeGraph feature surface |
You want declarative pattern matching (MATCH (a)-[:KNOWS]->(b)) | You need fine-grained traversal control, custom steps, or lambdas |
| Your queries are read-mostly patterns and projections | You need graph algorithms, OLAP, or features Cypher does not expose |
For anything Cypher cannot express, the equivalent Gremlin query always works — examples below show both.
Calling the Cypher API
Cypher statements are submitted to the HugeGraph Server through the REST endpoint:
When server authentication is disabled, no Authorization header is required; when authentication is enabled,
standard Basic (RFC 4648 Base64, e.g. curl -u) or Bearer <token> credentials are supported.
See the Cypher REST API reference for the full request and response format.
Example:
From the Java client, use CypherManager (see hugegraph-client):
Basic examples
The examples below assume a graph with person vertices (name, age, city properties) and knows edges.
Before running them, note:
- Property predicates in
WHERE(such asWHERE n.age > 30) require covering indexes (e.g. aRANGEindex onperson.age). - On schemas with non-nullable properties or
PRIMARY_KEYstrategy, create statements must provide required attributes and primary keys; create vertices with complete properties separately before creating connecting edges.
Read — MATCH / WHERE / RETURN
Create — CREATE
Update — SET / REMOVE
Delete — DELETE / DETACH DELETE
Aggregation
Gremlin equivalents
Every Cypher statement is translated to Gremlin internally. When a Cypher feature is unsupported, write the traversal directly:
| Cypher | Gremlin equivalent |
|---|---|
MATCH (n:person) WHERE n.name='marko' RETURN n | g.V().hasLabel('person').has('name','marko') |
MATCH (a)-[:knows]->(b) RETURN b | g.V().out('knows') |
CREATE (n:person {name:'x'}) | g.addV('person').property('name','x') |
MATCH (n) DETACH DELETE n | g.V().drop() |
MATCH (n:person) RETURN count(n) | g.V().hasLabel('person').count() |
Tip: You can inspect generated underlying Gremlin traversals via EXPLAIN MATCH (n:person) RETURN n (in the translation field of the response) to draft
equivalent traversals. PROFILE is not supported.
Limitations
- Parameterized query rules: Parameter bindings are supported via JSON request bodies (
{"cypher": "...", "parameters": {...}}, up to 16 top-level parameters; group additional properties into a nested Map and reference fields explicitly). Referencing an undeclared$paramresults in an execution error; explicitnullis supported. - Partial clause coverage: Certain advanced openCypher constructs (such as map projections and complex functions) are currently unsupported and fail during parsing and validation.
- No
CALLprocedures: Graph algorithms (shortest path, k-out, personalrank, etc.) are available via the traverser REST APIs or Gremlin instead of CypherCALLprocedures. - Single statement per request: Multi-statement scripts are not supported; submit one statement per call.
When a statement fails validation or execution, the server returns structured error details under status.attributes.errors with code, message, and
hint. The Gremlin equivalent is the recommended fallback.