neo4j - Potential inconsistency in creating relationships in cypher when we don't use directions -


i getting confused way relationships created through cypher. under impression _src-[:likes]- _dst creates bidirectional relationship looks not case _src-[:likes]- _dst == _src<-[:likes]- _dst (example provided below)
let's create following graph using _src[:likes]-_dst notation ( using '-' opposed '->')

create (_u1 {type:"user",`name`:"u1",userid:'u1' })  , (  _u2 {type:"user",`name`:"u2",userid:'u2'} )  , (  _u3 {type:"user",`name`:"u3",userid:'u3' })  , (  _u4 {type:"user",`name`:"u4",userid:'u4' })  , (  _u5 {type:"user",`name`:"u5",userid:'u5'}) ,  (_u6 {type:"user",`name`:"u6",userid:'u6'}),   (_f1 {type:"item",`name`:"f1",itemid:'f1' })  , (  _f2 {type:"item",`name`:"f2",itemid:'f2' })  , (  _f3 {type:"item",`name`:"f3",itemid:'f3' })  , (  _f4 {type:"item",`name`:"f4",itemid:'f4'}) ,  (_f5 {type:"item",`name`:"f5",itemid:'f5'}),   _u1-[:`likes`{likevalue:3}]-_f1 , _u1-[:`likes` {likevalue:13}]-_f2 , _u1-[:`likes` {likevalue:1}]-_f3 , _u1-[:`likes` {likevalue:5}]-_f4,  _u2-[:`likes`{likevalue:7}]-_f1 , _u2-[:`likes` {likevalue:13}]-_f2 ,  _u2-[:`likes` {likevalue:1}]-_f3,  _u3-[:`likes`{likevalue:5}]-_f1 , _u3-[:`likes` {likevalue:8}]-_f2 , _u4-[:`likes`{likevalue:5}]-_f1  ,_u5-[:`likes` {likevalue:8}]-_f2,_u6-[:`likes` {likevalue:8}]-_f2;  

my impression way, tell neo4j created bidirectional relationship. now, @ following query

neo4j-sh (?)$ start n=node(*) match n-[:likes]->m has(n.type) , n.type='user' return n,m; ==> +-------+ ==> | n | m | ==> +-------+ ==> +-------+ ==> 0 row  

but opposite works

neo4j-sh (?)$ start n=node(*) match n-[r]->m has(n.type) , n.type="item" return n,m limit 3; ==> +-----------------------------------------------------------------------------------------+ ==> | n                                          | m                                          | ==> +-----------------------------------------------------------------------------------------+ ==> | node[7]{type:"item",name:"f1",itemid:"f1"} | node[4]{type:"user",name:"u4",userid:"u4"} | ==> | node[7]{type:"item",name:"f1",itemid:"f1"} | node[3]{type:"user",name:"u3",userid:"u3"} | ==> | node[7]{type:"item",name:"f1",itemid:"f1"} | node[2]{type:"user",name:"u2",userid:"u2"} | ==> +-----------------------------------------------------------------------------------------+  

the question why a-[:likes]-b = a<-[:likes]-b ?
create 2 more nodes , relationship instructed in cypher manual

    create (_u7 {type:"user",`name`:"u7",userid:'u7' });     create (_f7 {type:"item",`name`:"f7",itemid:'f7' });  start src=node(*),dst=node(*) src.name='u7' , dst.name='f7' create src-[:likes{likevalue:3}]-dst;     neo4j-sh (?)$ start n=node(*) match n-[r]->m has(n.type) , n.type="user" return n,m limit 3;     ==> +-------+     ==> | n | m |     ==> +-------+     ==> +-------+     ==> 0 row  

same results, can't query user item can item user
if use following method things change

create (_u {type:"user",`name`:"u8",userid:'u8' })  , (  _f {type:"user",`name`:"f8",userid:'f8'} ), _u-[:likes{likevalue:2}]-_f; neo4j-sh (?)$ start n=node(*) match n-[r]->m has(n.type) , n.type="user" return n,m limit 3; ==> +-------------------------------------------------------------------------------------------+ ==> | n                                           | m                                           | ==> +-------------------------------------------------------------------------------------------+ ==> | node[19]{type:"user",name:"f8",userid:"f8"} | node[18]{type:"user",name:"u8",userid:"u8"} | ==> +-------------------------------------------------------------------------------------------+  

what going on? these questions
1- why create _src-[:likes]-_dst not create bidirectional relationship?
2- if can't why allow _src-[:likes]-_dst relationship creation? why not force people use directions when creating relationships?
3- difference between 2 methods used create relationships? (u7-f7 , u8-f8)

you can't create bidirectional relationship using _src[:likes]-_dst

in neo4j, relation can , must have single direction. represent bidirectional, have 2 options:

a) create relation direction ignore when querying (_src[:likes]-_dst match both directions when part of match clause)

b) create 2 relations- 1 in either direction

it appears if execute create without direction such _src[:likes]-_dst, incoming relation created _src


Comments