Neo4j Query Cypher Statement
Recently, the nosql database neo4j has been used, and the cypher statement has been used for its comprehensive query learning.
Sharing summary:
1. According to the index as nePort, fuzzy query all nodes for id. Sort by id, limit only goes to the first 10 records
start n = node:nePort('id:*')
match (x)-[:NE_PORT]->(n)
return n,x
order by n.id limit 10
2 .This query is much more than 1 query, match matches the relationship between nodes, first obtains it according to the index query, starting point n, in the matching relationship, [: relationship name], a->b means from a to b.
This query, Is to obtain the existence of a node relationship ambition n, and the relationship is NE_PORT, the starting point x
start n = node:nePort('id:*')
match (x)-[:NE_PORT]->n
return n.type,n.id ,n.speedId,n.code,n.name,n.optical,n.used,n.serial,x.id
order by n.id skip 0 limit 10; 3If
the fuzzy query node id attribute contains 11, the node.
START ne=node: ne('id=*11*') return ne
4. Match all subordinates [:VC*]
START ne=node(4106557) MACTH ne-[:NE_PORT]->port-[:VC*] -vc where vc.vtag=0 RETURN vc;
5. Only the nodes whose layer 2 relationship is VC are matched.
START ne=node(4106557) MATCH ne-[:NE_PORT]->port-[:VC*1..2]->vc WITH vc WHERE vc.vtag? = 0 RETURN vc;
6. Conditions, fuzzy query. Query label contains NEs in Zhongshan
start n=node(3) match n-[:NE]-ne where ne.label =~ '.*Zhongshan.*' return ne.id, ne.label, ne.name;
Query Syntax (Cyphe Query Language)
neo4j's own graph-based search algorithm implements a set of query language parsing and provides some common aggregation functions (max, sum, min, count, etc.).
Ø START: The starting point in the graph, obtained by element ID or so search.
Ø MATCH: The matching mode of the graph, bound to the starting point.
Ø WHERE: filter condition.
Ø RETURN: Return what is required.
Syntax example:
Join query:
start n=(1) match (n)-[:BLOCKS]->(x) return x
Where condition:
start n=(2, 1) where (n.age < 30 and n.name = "Tobias") or not(n.name = "Tobias") return nAggregate
function:
start n=(2,3,4) return avg(n.property)
Order:
start n=(1,2,3) return n order by n.name DESC
pagination:
start n=(1,2,3,4,5) return n order by n.name skip 1 limit 2
START n=node( *) return n skip 1 limit 2
count:
START n=node(*) RETURN count(*);
START n=node(*) RETURN "Hello Graph with "+count(*)+" Nodes!" as welcome;
start n = node:nePort('id:*') return n skip " + pageNo + " limit " + pageSize;
the following are a few examples of using parameters in JAVA:
node ID parameter
1
2
3
Map<String, Object> params = new HashMap<String, Object>();
params.put( "id", 0 );
ExecutionResult result =
engine.execute("start n=node({id}) return n.name", params );
node object Parameters
1
2
3
Map<String, Object> params = new HashMap<String, Object>();
params.put( "node", andreasNode );
ExecutionResult result =
engine.execute("start n=node({node}) return n.name", params );
多节点ID参数
1
2
3
Map<String, Object> params = new HashMap<String, Object>();
params.put( "id", Arrays.asList( 0, 1, 2 ) );
ExecutionResult result =
engine.execute("start n=node({id}) return n.name", params );
字符串参数
1
2
3
4
Map<String, Object> params = new HashMap<String, Object>();
params.put( "name", "Johan" );
ExecutionResult result =
engine.execute("start n=node(0,1,2) where n.name = {name} return n", params );
索引键值参数
1
2
3
4
5
Map<String, Object> params = new HashMap<String, Object>();
params.put( "key", "name" );
params.put( "value", "Michaela" );
ExecutionResult result =
engine.execute("start n=node:people({key} = {value}) return n", params );
索引查询参数
1
2
3
Map<String, Object> params = new HashMap<String, Object>();
params.put( "query", "name:Andreas" );
ExecutionResult result =
engine.execute("start n=node:people({query}) return n", params );
SKIP和LIMIT的数字参数
1
2
3
4
5
Map<String,Object> params = new HashMap<String, Object>();
) The node named A in the RETURN n index will be returned. Result: call example: db = new ImpermanentGraphDatabase();
engine = new ExecutionEngine( db );
CypherParser parser = new CypherParser();
ExecutionEngine engine = new ExecutionEngine(db);
Query query = parser.parse( "start n=(0) where 1=1 return n" );
ExecutionResult result = engine.execute( query );
assertThat( result.columns(), hasItem( "n" ) );
Iterator<Node> n_column = result.columnAs( "n" );
assertThat( asIterable( n_column ), hasItem(db.getNodeById(0)) );
assertThat( result.toString(), containsString("Node[0]") );
neo4j query cypher utterance
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326387629&siteId=291194637
Recommended
Ranking