yAsH
yAsH

Reputation: 3405

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?

Upvotes: 5

Views: 2513

Answers (1)

Mattias Finné
Mattias Finné

Reputation: 3054

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.

Upvotes: 9

Related Questions