Query based on relationships

Hello People,
I need help in optimizing my Neo4j Queries based on some scenarios:

  1. If( the rating of the Distributor is lessened because of quality issues)
    (If there is another Distributor that supplies the same item is available) Then(Order from the new Distributor with a good rating)

MATCH n=(d:Distributor)-[de:Delivers]->(r:Retailer)-[s:Sells]->(p:Product) WHERE d.name = "Costco" and p.name = "a"
SET d.Rating = 3.5
WITH d,r,p
MATCH (d)-[de: Delivers]->(r)-[s: Sells]->(p)
WHERE p.name = "a"
AND d.rating > 3.5
WITH collect(d) as goodDistributors
UNWIND goodDistributors as distributorList
OPTIONAL MATCH (r:Retailer)-[o:Orders{Product:"a"}]->(d:Distributor{name:"Costco"})
DELETE o
FOREACH (d2 in distributorList| CREATE (r)-[o2:Orders{Product:"a"}]->( d2))

Any help will be appreciated.

Hi,

To find all the distributors for the product p="a" with rating greater than 3.5, try this query:

MATCH (d:Distributor)-[de:Delivers]->(r:Retailer)-[s:Sells]->(p:Product)
WHERE p.name = "a" and d.name <> "Costco"
AND d.rating > 3.5

Use this list to perform other activities.

-Kamal

1 Like