1
votes

This is a design question and need a guideline for performance and maintenance considerations.

Is it advisable for a label indicate relationship with other node/label?

Approach-1: 
create (n:Actor:Director {name:'Clint Eastwood'})
create (n:Movie {name:'Gran Torino'})

MATCH (a:Actor {name:'Clint Eastwood'}), (m:Movie {name:'Gran Torino'})
CREATE (a)-[:ACTED_IN]->(m)

In this case, Actor / Director is really a relationship of a person to a Movie node. So should it just be created as a Person node with two relationships with a movie node if the person is both actor and director in a movie?

Approach-2: 
create (n:Person {name:'Clint Eastwood'})
create (n:Movie {name:'Gran Torino'})

MATCH (p:Person {name:'Clint Eastwood'}), (m:Movie {name:'Gran Torino'})
CREATE (p)-[:ACTOR]->(m)

MATCH (p:Person {name:'Clint Eastwood'}), (m:Movie {name:'Gran Torino'})
CREATE (p)-[:DIRECTOR]->(m)

Approach-2 seems better engineering wise, however the Neo4J example documentation also referes to Approach-1 (ref: https://neo4j.com/developer/kb/how-do-i-report-on-nodes-with-multiple-labels/)

So which one is cleaner, better, and more efficient in the long run?

1

1 Answers

1
votes

Generally labels are used to group nodes and indicates which role a node represent in the whole graph.

The example pointed by you shows that Clint Eastwood is part of the Actors group and part of the Directors group.This does not mean that he plays the role "actor" and "director" in all movies he works. In the example Clint Eastwood has acted and directed 'Gran Torino'. But what you will do if you need make a relationship between Clint Eastwood and a movie he only acted?

The cleaner, better, and more efficient approach depends on your domain and what are you doing. Maybe a mix of both is a good ideia.

If in any point of time you will need query your database looking for actors or directors, I believe is a good ideia to use labels :Actor and :Director to group these nodes. If not, you don't need these labels. Also, I recommend that you use the relationship to indicate what are the meaning of the relation between a :Person and a :Movie. That is, relationships like ()-[:ACTED_IN]->() and ()-[:DIRECTED]->().