Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return labels for a node using Cypher

Tags:

neo4j

cypher

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.

like image 595
joe Avatar asked Oct 01 '13 20:10

joe


People also ask

What would you add to the cypher code to return the labels for each node?

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

How do you represent a node in Cypher?

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

What Cypher statement returns the keys used for properties on nodes and relationships?

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!"}

How do I create a node label in Neo4j?

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)


1 Answers

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()

like image 92
arijeet Avatar answered Sep 21 '22 15:09

arijeet