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.

Neo4J beginner: issues with CALL apoc.create.relationship

`CALL apoc.load.xls('file:///filename.xlsx','Nodes') YIELD map as m

CALL apoc.create.node([m.fromNodeLabel], {name:m.fromNodeName,value:m.fromValue,instanceID:m.InstanceID}) YIELD node as f

CALL apoc.merge.node.eager([m.toNodeLabel], {name:m.toNodeName,instanceID:m.InstanceID}) YIELD node as t

CALL apoc.create.relationship(f,m.relship,{weight:10}, t)`

Variables YIELDed by the Create & Merge statements cannot be passed into the create.relationship statement without...something...?

1 ACCEPTED SOLUTION

intouch_vivek
Graph Steward

Hi warwick,

Please mention Yield for apoc.create.relationship(f,m.relship,{weight:10}, t)
i.e.,
CALL apoc.load.xls('file:///filename.xlsx','Nodes') YIELD map as m CALL
CALL apoc.create.node([m.fromNodeLabel], {name:m.fromNodeName,value:m.fromValue,instanceID:m.InstanceID}) YIELD node as f
CALL apoc.create.node([m.toNodeLabel], {name:m.toNodeName,instanceID:m.InstanceID}) YIELD node as t
CALL apoc.create.relationship(f,m.relship,{weight:10}, t) yield rel as rel return rel,f,t

View solution in original post

8 REPLIES 8

warwick ,
could you please share the error you are getting .

intouch_vivek
Graph Steward

Hi warwick,

Please mention Yield for apoc.create.relationship(f,m.relship,{weight:10}, t)
i.e.,
CALL apoc.load.xls('file:///filename.xlsx','Nodes') YIELD map as m CALL
CALL apoc.create.node([m.fromNodeLabel], {name:m.fromNodeName,value:m.fromValue,instanceID:m.InstanceID}) YIELD node as f
CALL apoc.create.node([m.toNodeLabel], {name:m.toNodeName,instanceID:m.InstanceID}) YIELD node as t
CALL apoc.create.relationship(f,m.relship,{weight:10}, t) yield rel as rel return rel,f,t

That did it - I did not realise you must include a YIELD on the APOC create.
THANK YOU!

If you are running a procedure all by itself then you don't need to do yield. If you are using somewhere in the middle of a cypher query you need to do yield.

This may sound like a stupid question - but how do we know exactly what is yielded by these calls? I could not find it in http://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/nodes-relationships/data-creation/

Please go through this link for YIELD https://neo4j.com/docs/cypher-manual/current/clauses/call/

If you need to use the output of a procedure use Yield. This use could be in Return statement or in other query etc.

Procedure apoc.create.relationship can just give you output node or relationship and that is what I did. In the neo4j documentation details of Yield is only given for generic procedures like CALL apoc.create.uuids(count) YIELD uuid, row.

There are 2 types of extensions in apoc.

Functions and Procedures.

Please see the documentation here
https://neo4j.com/docs/labs/apoc/current/overview/

Functions - They are inline functions that can return a single value.

Ex: apoc.node.degree.in

Functions can be used in where conditions, WITH etc.

Ex:

MATCH (n) WHERE apoc.node.degree.in(n, 'NEXT') > 0 

This query returns all the nodes which has more than one incoming NEXT relationship.

Procedures:
These can return more than one values. Those values are handled using YIELD.

If you search in the doc you can find signature as

apoc.create.relationship(from :: NODE?, relType :: STRING?, props :: MAP?, to :: NODE?) :: (rel :: RELATIONSHIP?)

You can see the return value here as only one (rel :: RELATIONSHIP?)

Hope this explains it better.

Procedure call inside a query does not support naming results implicitly (name explicitly using YIELD instead) (line 4, column 1 (offset: 294))
"CALL apoc.create.relationship(f,m.relship,{weight:10}, t)"
^