Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j - get all nodes belonging to an index using Java API

Say that I have an index named "user". How do I get all the nodes belonging to that index using Neo4j-Java Api?

I tried the code below

val nodeIndex = getNodeIndex("article").get
val nodes = nodeIndex.getGraphDatabase().getAllNodes()

But, I got all the nodes present in the db. How do I solve this?

like image 866
yAsH Avatar asked May 24 '13 08:05

yAsH


People also ask

How can I see all nodes in Neo4j?

You can show everything with simple MATCH (n) RETURN n , as offical documentation suggests. START n=node(*) RETURN n from Neo4j 2.0 is deprecated: The START clause should only be used when accessing legacy indexes (see Chapter 34, Legacy Indexing). In all other cases, use MATCH instead (see Section 10.1, “Match”).

How do I return all nodes and relationships in Neo4j?

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.

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


1 Answers

You should use "get" or "query" on the nodeIndex, like:

IndexHits<Node> allArticles = nodeIndex.query( "*:*" );
... do stuff ...
allArticles.close();

or

Node myArticle = nodeIndex.get( "name", "MyArticle" ).getSingle();

What you did above was to regardless of the index, get the graph database and return all nodes.

like image 50
Mattias Finné Avatar answered Oct 18 '22 07:10

Mattias Finné