cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to access relationships and form a query that recommends restaurants?

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?

1 REPLY 1

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

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online