The query of Knowledge Graph uses cypher language, which has rich expressive force and high query efficiency. In Graph Database, it acts on relational database. The SQL language is equivalent.
MATCH is used to query about nodes, relationships, and attributes, similar to SELECT in SQL.
RETURN returns the Search Result after the MATCH search is complete, so MATCH must be used with RETURN.
The WHERE clause is used to filter the search.
WHERE can be combined with the function exists (), string matching starts with, ends with, contains, logical matches in, not, and, or, and regular expression matches for more granular queries.
The LIMIT clause is used to limit the number of matches returned.
Here are some common Graph Query commands and examples:
Query command | The cypher syntax | Examples |
Finds the specified Entity Type | match (n:Entity Type) return n | Match (n: river) return n |
Find an entity for a certain attribute | Match (n: Entity Type { attribute name: 'attribute value' }) return n | Match (n: river { name: 'Dadu River' }) return n |
Find a type of relationship | match p = (n)-r->(m) return p | match p = (n)-[r:contains]->(m) return p |
In the graph data, we often need to perform a deeper association query based on the relationship. The following are examples of several common association query statements:
Serial number | The cypher statement | Meaning |
1 |
MATCH p = (n: river { name: 'Dadu River' })- r- () RETURN p | Query All relations of Dadu River (no arrow direction) |
2 |
MATCH p = (n: river { name: 'Dadu River' })- [r: flow through]-> () RETURN p | Query the flowing relationship of Dadu River (with arrow direction) |
3 |
MATCH p = (n)- [r: flow through]-> (m: area {name: 'Ya'an'}) RETURN p or MATCH p=(n)- [r: flow through]-> (m: area) where m.Name='Ya'an' return n.name. | Inquire about all the rivers that flow through the Hongya area. |
4 |
MATCH p = (n)- [r:flow through]-> (m)where m.name in ['Luding County','Danba County'] return n.name | Inquire about rivers flowing through both Luding and Danba counties |
5 |
MATCH p = (n: hydropower station {name:'Pubugou Hydropower Station'})- [:river-> (m)- : [:flow through-> (e) RETURN e | Find out which areas the river where Pubugou Hydropower Station is located flows through |
Note: When performing graph queries in YuKon with AgensGraph, entity attribute fields must be in lowercase.
The SuperMap iServer Knowledge Graph service provided The query resource is used to obtain a collection of entity and relationship information.
1. Click the published Knowledge Graph service on the iServer service management page to get the Server Address. Uch as http://localhost:8090/iserver/services/knowledgeGraph-test/restjsr
2.Execute a GET request on a query resource to obtain a collection of entity and relationship information. Example URI such as:
http://localhost:8090/iserver/services/knowledgeGraph-test/restjsr/graph/query.rjson?cypherQuery=match%20a=((p)-[r]->(q: Courtyard 2D { server:% 27 -- server = E:% 2 F00testdata% 2FKnowledge Graph% 2F Base Geo Entity% 2 FCourtyard.udbx% 20--dbType = UDBX% 20--dataset = Courtyard2D% 27 }))% 20 return% 20a% 20 limit% 2010;