Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find all nodes with a specific label using the Java API in Neo4j 2.0.x?

Tags:

java

labels

neo4j

I need to find a specific node in the entire graph using the Java low level API. I used to do this using the Reference node in versions 1.x but that concept has been removed with the 2.0 release.

I thought I could use labels to do this: I would assign a label to this node (and only this node) when it is created. Subsequently I would get all the nodes with this particular label, which should return a single hit, ie the special node I'm looking for. Unfortunately I can't find a way to look up all nodes having a specific label using the Java API.

I am able to do it with Cypher but I'd like this look up to be as fast as possible, so saving the cost of query parsing, planning and execution would be great.

like image 963
Zack Avatar asked Feb 25 '14 20:02

Zack


People also ask

What is the syntax for getting all the nodes under specific label in Neo4j?

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 can I see all nodes in Neo4j?

Following is the query which returns all the nodes in Neo4j database. Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in the following screenshot.

How do I return all nodes and relationships in Neo4j?

Return all elements When you want to return all nodes, relationships and paths found in a query, you can use the * symbol.


2 Answers

This method GlobalGraphOperations.getAllNodesWithLabel(Label label) returns all nodes with the specified label.

like image 66
Lisa Li Avatar answered Oct 09 '22 01:10

Lisa Li


You can use GlobalGraphOperations.at(gdb).getAllRelationshipTypes() to get all nodes with the label, and gdb is your graph database.

like image 27
LoveTW Avatar answered Oct 09 '22 01:10

LoveTW