How do I return all the labels for a node using a Cypher query? Note that I don't know the node id in advance, I do some sort of index match to get it.
If you want to get the labels of a specify node, then use labels(node) ; If you only want to get all node labels in neo4j, then use this function instead: call db. labels; , never ever use this query: MATCH n RETURN DISTINCT LABELS(n) .
Node or Relationship Properties To represent these in Cypher, we can use curly braces within the parentheses of a node or the brackets of a relationship. The name and value of the property then go inside the curly braces. Our example graph has both a node property ( name ) and a relationship property ( since ).
When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. Node[0]{name:"A",age:55,happy:"Yes!"}
Create a Node with Multiple Labels To create multiple labels with a single node, you have to specify the labels for the node by separating them with a colon " : ". Syntax: CREATE (node:label1:label2:. . . . labeln)
You can get labels by using the labels()
method.
Example (Neo4j 2.0):
Lets say you have the "name" property indexed and would like to search on that basis, the following query would give you all nodes and their labels which have name = "some_name"
MATCH (r) WHERE r.name="some_name" RETURN ID(r), labels(r);
If you know one of the labels of the starting node, that's even better. For some known label called "Label", this query would give you all nodes along with all labels that are associated with the node.
MATCH (r:Label {name:"some_name}) RETURN ID(r), labels(r);
Need more assistance? Go through the Cypher docs! for labels()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With