Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do having multiple labels for a node in Neo4j make any sense?

Following this post from Neo4j's google group I have to say that I don't see any benefits when using this multiple-label-thing but rather, on the contrary, IMHO it just adds complexity for what a uniqueness constraint is. It could also tempt the user to introduce inheritance into the data model which would cause frustration since that's not possible at all...

like image 449
ppareja Avatar asked Jan 28 '14 09:01

ppareja


People also ask

Can a Neo4j node have more than one label?

If you look closely, the labels column is in the form of an array, which means that a single node can have multiple labels. Also, with cypher projection, we can provide a virtual label, as shown in the query.

Is it possible for a node to have multiple labels?

Create a node with multiple labelsTo add labels when creating a node, use the syntax below. In this case, we add two labels.

How many labels can a node have in Neo4j?

Nodes can have zero or more labels to define (classify) what kind of nodes they are.

What are labels in Neo4j?

Neo4j recently introduced the concept of labels and their sidekick, schema indexes. Labels are a way of attaching one or more simple types to nodes (and relationships), while schema indexes allow to automatically index labelled nodes by one or more of their properties.


1 Answers

Labels have not the notion of just representing a type, they are rather roles which are viable in different contexts.

So in one role, certain attributes and relationships of a node might matter and in another role (label) a different set (that might intersect with the first one).

We stayed away from inheritance as it opens a new can of worms, and we favor composition. So you'd rather compose a node whole as the sum of its parts. You can also mimic an inheritance by also attaching the "super"-types as labels to the child elements in your hierarchy.

Node labels can also be used to separate subgraphs in a larger graph, e.g. label the proteins that are active in human pathways and phylo pathways with those labels. So you can quickly select a part of the graph that you're interested in.

Those separate subgraphs can also come from different domains, like geo,social,catalogue,supplier that are combined in a single graph.

And multiple labels also make sense to separate "technical" namespaces of your graph that are used to represent "in-graph-indexes" from your "domain"-labels.

Regarding uniqueness - all uniqueness constraints for the existing labels and properties on your nodes are enforced at the same time. If they cannot be resolved on insert or update the operation will fail.

like image 56
Michael Hunger Avatar answered Sep 23 '22 20:09

Michael Hunger