Skip to content

Instantly share code, notes, and snippets.

View vladbatushkov's full-sized avatar
🥥
Sabai sabai

Vlad Batushkov vladbatushkov

🥥
Sabai sabai
View GitHub Profile
@vladbatushkov
vladbatushkov / Workshop_And_Tutorial_Useful_Links.md
Last active August 27, 2019 15:54
All useful links for Neo4j Workshop& Tutorial
@vladbatushkov
vladbatushkov / Aggregation_example.cypher
Created July 30, 2019 16:10
Robert total calls and max duration.
MATCH (p1:Person)-[:OUT]->(c:Call)
WHERE p1.name = "Robert"
RETURN p1.name as name, count(c) as total_calls, max(c.duration) as max_duration
@vladbatushkov
vladbatushkov / Algorithms.cypher
Last active July 31, 2019 15:37
Apply algorithms to sub-graph of people
// Dijkstra
MATCH (p1:Person { name:'Omar' }), (p2:Person { name:'Ronin' })
CALL algo.shortestPath.stream(p1, p2, 'duration') YIELD nodeId, cost
RETURN algo.asNode(nodeId).name AS name, cost
// Dijkstra Projection
MATCH (p1:Person { name: 'Omar' }), (p2:Person { name: 'Ronin' })
CALL algo.shortestPath(p1, p2, 'cost',{
nodeQuery:'MATCH (p:Person) RETURN id(p) as id',
relationshipQuery:'MATCH (p1:Person)-[c:COMMUNICATE_WITH]->(p2:Person) RETURN id(p1) as source, id(p2) as target, c.duration as weight',
@vladbatushkov
vladbatushkov / Top_10_talking_A.cypher
Last active August 1, 2019 18:13
Top 10 talking persons with name starts on A.
// How to works with Date Type here:
// https://neo4j.com/docs/cypher-manual/current/syntax/temporal/#cypher-temporal-accessing-components-temporal-instants
MATCH (p:Person)-[]->(c:Call)
WITH p.number as num, p.name as name, sum(c.duration) as d
WHERE name STARTS WITH "A"
RETURN num, name, d
ORDER BY d DESC
LIMIT 10
@vladbatushkov
vladbatushkov / 10_minutes_OUT_and_5minutes_IN.cypher
Created July 14, 2019 16:21
All persons recived 10 minutes calls in July and made 5 minutes calls.
MATCH (c1:Call { duration: 10 })<-[:IN]-(p:Person)
WHERE (p)-[:OUT]->(:Call { duration: 5 }) AND c1.from.month = 7
RETURN p
@vladbatushkov
vladbatushkov / Communication.cypher
Last active August 21, 2019 16:56
Create COMMUNICATE_WITH relationship between persons.
// Check the data
MATCH (p1:Person)-[:OUT]->(c:Call)<-[]-(p2:Person)
WHERE c.duration > 0
RETURN p1.name, p2.name, sum(c.duration) as duration, count(c) as calls
ORDER BY duration DESC
LIMIT 10
// Check one pair
MATCH (p1:Person { name: "Kara" })-[*2]-(p2:Person { name: "Hailee" })
RETURN p1, p2
@vladbatushkov
vladbatushkov / Bangkok_to_Pattaya_calls.cypher
Last active August 1, 2019 18:06
All men from Bangkok who called to women in Pattaya.
// How to use DISTINCT https://neo4j.com/docs/cypher-manual/current/clauses/return/#return-unique-results
MATCH (:City { name: "Bangkok" })<-[:FROM]-(p1:Person { gender: "Man" })
MATCH (p1)-[:OUT]->(:Call)<-[:IN]-(p2:Person { gender: "Woman" })-[:FROM]->(:City { name: "Pattaya" })
RETURN p1.name as fromBangkok, p2.name as toPattaya
@vladbatushkov
vladbatushkov / calls_in_Feb_by_day.cypher
Last active August 1, 2019 18:08
Day in February with lowest number of calls.
// How to use NOT: https://neo4j.com/docs/cypher-manual/current/clauses/where/#filter-on-patterns-using-not
MATCH (c:Call)
WHERE c.from.month = 2
RETURN date(c.from), count(c) as calls
ORDER BY calls
LIMIT 10
@vladbatushkov
vladbatushkov / calls_by_Robert.cypher
Last active July 30, 2019 16:03
Robert called to this persons.
MATCH (p1:Person)-[:OUT]->(:Call)<-[:IN]-(p2:Person)
WHERE p1.name = "Robert"
RETURN p2
@vladbatushkov
vladbatushkov / calls_in_May.cypher
Created July 10, 2019 16:15
How many calls started in May?
MATCH (c:Call)
WHERE c.from.month = 5
RETURN count(c) as calls