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

Say I have an index called "user". How to get all nodes belonging to this 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 db. How to solve this?

+4
source share
1 answer

You should use "get" or "query" for nodeIndex, for example:

 IndexHits<Node> allArticles = nodeIndex.query( "*:*" ); ... do stuff ... allArticles.close(); or Node myArticle = nodeIndex.get( "name", "MyArticle" ).getSingle(); 

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

+9
source

Source: https://habr.com/ru/post/1482522/


All Articles