Display property in place of relationship name

I'm running Neo4j Community v.3.5.7 on a Mac.

I have a schema that looks something like this:

(:Person { Name: Name, FullName: FullName, Level: Level, Strength: Strength})
(:Strength {Name: Strength})

When I do a query,

MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility" 
CREATE (p)-[r:Responsibility]->(s)
RETURN p,s

I see this:
sample

How do I get the relationship 'lines' (e.g. labeled as "Responsibility") to be labeled with the Person's "Level" (an integer value property from the Person schema) instead of the name of the relationship?

Hello Steve and welcome to the community!

The level/strength properties are set for the nodes in your example. If you want the same properties for the relationships, you would simply use the SET clause to set the values. Also, I would recommend you use Merge for creating the relationships to ensure you do not create duplicate relationships.

For example:

MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
MERGE (p)-[r:Responsibility]->(s)
SET r.Strength = "xxx"
RETURN p,s

This will set the property for the relationship. Ideally you do not want to duplicate data (node property/relationship property) in the graph.

Elaine

Thanks, but "Responsibility" still shows up as the label for the relationship - I want it to display the Person's "Level" instead.

Use apoc.create.relationship for this.

As the 'Level' property values are integers you will have a problem in selecting the relationship as the relationship label has to be a string. Here are the workarounds for this problem,

1: Use Level values (needs to be converted to string)

MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
WITH p, s
CALL apoc.create.relationship(p, toString(p.Level), {}, s) YIELD rel
RETURN p, s;

steve2

To select relationship "8" workaround:

MATCH (p:Person)-[r]-(s)
WHERE Type (r) = "8"
RETURN p, s;
steve3

2: Prefix Level value with letter "S":

MATCH (p:Person),(s:Strength)
WHERE p.Strength = s.Name AND p.Strength = "Responsibility"
WITH p, s
CALL apoc.create.relationship(p, ("S" + toString(p.Level)), {}, s) YIELD rel
RETURN p, s;

steve1

You can easily filter by relationship type:

MATCH (p:Person)-[:S8]-(s)
RETURN p, s;

steve4

Hope this works for you.

F-A-N-T-A-S-T-I-C !!

I used 2: Prefix Level value with letter "S" and it was the perfect answer for what I was trying to accomplish.

Thank you so much for your time and trouble