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

1

8

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...

Tamanaha answered 28/1, 2014 at 9:57 Comment(1)
You can look at this answer: https://mcmap.net/q/1327392/-how-to-work-with-type-hierarchies-in-neo4jDeoxidize
N
11

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.

Nichrome answered 28/1, 2014 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.