Neo4j create edges with multiple labels/properties

Viewed 783

I am new to neo4j but I am trying to create this simple graph where edges can have multiple labels (or is it properties??)

basically

          clicked
User A ---------------------------------------------------------->  item B
       {created at: timestamp, user key: some user specific key}

So far I am able to create

                     clicked
User A ---------------------------------------------------------->  item B
           {created at: timestamp}



                  clicked
User A ---------------------------------------------------------->  item B
       |    {created at: timestamp}                              ^
       L_________________________________________________________|

But instead of two edges, I want to have these two attributes in single edge? Is that feasible? Cypher query preferred.

1 Answers

Yes you can- these are relationship/edge properties. A relationship does not have labels, just a type and properties.

To create the relationship with all properties in one go, you can do

MATCH (u:User {name:"A"})
MATCH (i:Item {name:"B"})
CREATE (u)-[r:CLICKED]->(i)
SET r.createdAt=$timestamp, r.userKey=$userkey

Or if you already have the relationship and want to add properties to it:

MATCH (u:User {name:"A"})
MATCH (i:Item {name:"B"})
MERGE (u)-[r:CLICKED]->(i)
SET r.createdAt=$timestamp, r.userKey=$userkey
Related