简体   繁体   English

如何使用Neo4j 2.0.x中的Java API找到具有特定标签的所有节点?

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

I need to find a specific node in the entire graph using the Java low level API. 我需要使用Java低级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. 我曾经使用版本1.x中的Reference节点执行此操作,但该概念已在2.0版本中删除。

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. 不幸的是,我找不到使用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. 我能够用Cypher做到这一点,但我希望看起来尽可能快,因此节省查询解析,规划和执行的成本将是巨大的。

此方法GlobalGraphOperations.getAllNodesWithLabel(Label label)返回具有指定标签的所有节点。

您可以使用GlobalGraphOperations.at(gdb).getAllRelationshipTypes()来获取带有标签的所有节点, gdb就是您的图形数据库。

The provided answer is deprecated . 提供的答案已弃用 The preferred method is now to use: GraphDatabaseService.findNodes(Label label) 现在使用的首选方法是: GraphDatabaseService.findNodes(Label label)

GraphDatabaseService.findNodesByLabelAndProperty (Label label, String propName, String propValue) might suit your bill.... GraphDatabaseService.findNodesByLabelAndProperty(Label label,String propName,String propValue)可能适合您的账单....

or you could save the id of the node when you create it initially, then you can call GraphDatabaseService.getNodeById(long id) - which would be, by far, the fastest way to retrieve a specific node. 或者你可以在最初创建它时保存节点的id,然后你可以调用GraphDatabaseService.getNodeById(long id) - 这是迄今为止检索特定节点的最快方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM