5

假设我有一个名为“用户”的索引。如何使用 Neo4j-Java Api 获取属于该索引的所有节点?

我尝试了下面的代码

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

但是,我得到了数据库中存在的所有节点。我该如何解决这个问题?

4

1 回答 1

9

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.

于 2013-05-24T09:14:34.000 回答