cypher - Create on NOT MATCH command for Neo4j's CQL? -


i have non-unique node (:neighborhood) uniquely appears [:in] (:city) node. create new neighborhood node , establish relationship if neighborhood node not exist in city. there can multiple neighborhoods have same name, each neighborhood must appear uniquely appear in property city.

following advice gil's answer here: return node if relationship not present, how can like:

match not (a:neighborhood {name : line.neighborhood})-[r:in]->(c:city {name : line.city}) on match set (a)-[r]-(c) 

so create new neighborhood node if doesn't exist in city.

**update:**i upgraded , profiled , still can't take advantage of optimizations...

profile load csv headers "file://thefile" line line limit 0 match (c:city { name : line.city}) merge (n:neighborhood {name : toint(line.neighborhood)})-[:in]->(c)  ;   +--------------+------+--------+---------------------------+------------------------------+ |     operator | rows | dbhits |               identifiers |                        other | +--------------+------+--------+---------------------------+------------------------------+ |  emptyresult |    0 |      0 |                           |                              | |  updategraph |    5 |      16 | anon[340], b, neighborhood, line |                 mergepattern | |  schemaindex |    5 |      10 |                   b, line | line.city; :city(name) | | columnfilter |    5 |      0 |                      line |            keep columns line | |       filter |    5 |      0 |           anon[216], line |                    anon[216] | |      extract |    5 |      0 |           anon[216], line |                    anon[216] | |        slice |    5 |      0 |                      line |                 {  autoint0} | |      loadcsv |    5 |      0 |                      line |                              | +--------------+------+--------+---------------------------+------------------------------+ 

i think use merge this:

match (c:city {name: line.city}) merge c<-[:in]-(a:neighborhood {name : line.neighborhood}) 

if haven't imported of cities, can create merge:

match (c:city {name: line.city}) merge c<-[:in]-(a:neighborhood {name : line.neighborhood}) 

but beware of eager operator:

http://www.markhneedham.com/blog/2014/10/23/neo4j-cypher-avoiding-the-eager/

in short: should run load csv (i assume that's you're doing here) twice, once load cities , once load neighborhoods.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -