cancel
Showing results for 
Search instead for 
Did you mean: 

Neo4j - Cypher query

mcron10
Node

Hello

I was wondering if you could help,

I am very new to Neo4j and would like some help with some Cypher queries. I have configured the nodes and relationships and would like to configure the following queries. I am looking for shortest path between sites using dijkstra algorithm.

  1. Cypher query - show the shortest path for "mark" to marks property "likes" value "chinese" Only show the streets in order and the restaurant name

mark ----> main ----> first ----> ninth ----> allchinese ----> chinese

  1. Cypher query - show the shortest path for "mark" to marks property "game" value "megabucks" Only show the streets in order and the casino name

mark ----> main ----> first ----> ninth ----> casino1 ----> megabucks

  1. Also using the current syntax for adding relationships how can I add an additional property - for example

Relationship type "route" property "route" add 2nd property "well lighted" value yes

Or is there a better way of adding a relationship with 2 properties

  1. If i can add the "well lighted" property to the streets how can I query

Cypher query - show the shortest path for "mark" to marks property "game" value "megabucks" prefer "well lighted" streets Only show the streets in order and the casino name

mark ----> main ----> first ----> ninth ----> casino1 ----> megabucks

Thanks for any help on this

Mark

################## NODES ##################################

CREATE (n1: person {id:1, name:'mark', likes:'chinese', game:'megabucks'})
CREATE (n2: street {id:2, zipcode:'89050', street:'main'})
CREATE (n3: street {id:3, zipcode:'89050', street:'first'})
CREATE (n4: street {id:4, zipcode:'89050', street:'ninth'})
CREATE (n5: restaurant {id:5, zipcode:'89050', street:'ninth', name:'allchinese'})
CREATE (n6: restaurant {id:6, zipcode:'89051', street:'first', name:'allburgers'})
CREATE (n7: menu {id:7, food:'chinese'})
CREATE (n8: menu {id:8, food:'burgers'})
CREATE (n9: casino {id:9, name:'casino1'})
CREATE (n10: casino {id:10, name:'casino2'})
CREATE (n11: slot {id:11, name:'megabucks'})
CREATE (n12: slot {id:12, name:'batman'})

################ RELATIONSHIPS #################################

MATCH (a {id:1}), (b {id:2}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:2}), (b {id:1}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:2}), (b {id:3}) MERGE (a)-[:route  {route:'100'}]->(b);
MATCH (a {id:3}), (b {id:2}) MERGE (a)-[:route  {route:'100'}]->(b);
MATCH (a {id:3}), (b {id:4}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:4}), (b {id:3}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:4}), (b {id:5}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:5}), (b {id:4}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:4}), (b {id:6}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:6}), (b {id:4}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:5}), (b {id:7}) MERGE (a)-[:serves  {serves:'10'}]->(b);
MATCH (a {id:7}), (b {id:4}) MERGE (a)-[:serves  {serves:'10'}]->(b);
MATCH (a {id:5}), (b {id:8}) MERGE (a)-[:serves  {serves:'10'}]->(b);
MATCH (a {id:8}), (b {id:5}) MERGE (a)-[:serves  {serves:'10'}]->(b);
MATCH (a {id:4}), (b {id:9}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:9}), (b {id:4}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:4}), (b {id:10}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:10}), (b {id:4}) MERGE (a)-[:route  {route:'10'}]->(b);
MATCH (a {id:9}), (b {id:11}) MERGE (a)-[:hosts  {hosts:'10'}]->(b);
MATCH (a {id:11}), (b {id:9}) MERGE (a)-[:hosts  {hosts:'10'}]->(b);
MATCH (a {id:10}), (b {id:12}) MERGE (a)-[:hosts  {hosts:'10'}]->(b);
MATCH (a {id:12}), (b {id:10}) MERGE (a)-[:hosts  {hosts:'10'}]->(b);

 

 

 

0 REPLIES 0
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.