Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-09-2022 08:23 AM
I have the following model:
LOAD CSV WITH HEADERS FROM "file:///restaurant_data.csv" AS data
MERGE(n1:Customer{name:data.Name, latitude:toFloat(data.Latitude),longitude:toFloat(data.Longitude)})
MERGE(n3:Restaurant{restaurantname:data.Restaurant, restlat:toFloat(data.Rest_lat), restlong:toFloat(data.Rest_long)})
MERGE (n1)-[r1:PLACES_ORDER{orderId:data.Order_ID,ordertimestamp: apoc.date.parse(data.Order_ts,'ms', 'dd-MM-yyyy HH:mm'),foodname:data.Food_Item}]->(n3)
RETURN *;
Now i want to fetch a customer's top 5 orders by timestamp. How do I do that in cypher? I was able to do when I had 3 nodes. Customer, Orders and Restaurants as :
MATCH(c:Customer{Name:"Ania"})-[:PLACES_ORDER]->(o:Orders)
WITH o ORDER BY o.OrderTimestamp DESC LIMIT 5
WITH [o.FoodName] as foods
MATCH (r:Restaurant)<-[:BELONGS_TO]-(o:Orders{FoodName:"Pommes"})
WHERE (o.FoodName in foods) AND NOT (:Customer{Name:"Angy"})-[:PLACES_ORDER]->(o:Orders)-[:BELONGS_TO]->(r:Restaurant)
RETURN distinct r.RestaurantName,foods
How do I use the same search query and access the relationship's property?
02-09-2022 08:47 AM
You can access relationship properties by binding the relationship to a variable, as done with nodes.
Example:
match(n:Employee)-[r:WORKS_FOR]->(c:Company)
where n.name = "Smith" and c.name = "Google"
return r.startDate, r.role
All the sessions of the conference are now available online