简体   繁体   English

如何从Java获取Neo4j图形数据库的节点数,如何从磁盘存储和重用graphdb?

[英]How can I get the number of nodes of a Neo4j graph database from java and can we store and reuse graphdb from disk?

I just started looking at neo4j to use it for my social-network related project. 我刚刚开始研究neo4j,以将其用于与社交网络相关的项目。 During this I came across the following code: 在此期间,我遇到了以下代码:

https://github.com/neo4j/neo4j/blob/1.9.M04/community/embedded-examples/src/main/java/org/neo4j/examples/EmbeddedNeo4jWithIndexing.java

While going through it (please refer to above link for code), I was struggling to know, how to get the total number of nodes added to a given graphDb . 在浏览过程中(请参阅上面的代码链接),我一直在努力地了解如何获取添加到给定graphDb的节点graphDb Is there any way to find it (total number of nodes) using graphDb or nodeIndex or referenceIndex or anything else? 有什么方法可以使用graphDbnodeIndexreferenceIndex或其他方式找到它(节点总数)? If yes, How? 如果是,如何?

I also need help to know, how to store the graphdb to any given path on disk? 我还需要帮助才能知道,如何将graphdb存储到磁盘上的任何给定路径? How to load this stored graphdb and perform operations on it like searching for a node/relationship etc? 如何加载此存储的graphdb并对其执行操作,例如搜索节点/关系等?

(There are several files like *.db, *.id, *.keys etc.. created at given DB_PATH when above code is executed. What are all those files useful for? Does any of those files contain nodes created? if yes, how can we use them?) (执行上述代码时,在给定的DB_PATH创建了多个文件,例如* .db,*。id,*。keys等。这些文件有什么用处?这些文件中是否包含创建的节点?如果是,我们如何使用它们?)

How can we access this graphDb from web-interfaces like, Dashboard at http://localhost:7474/webadmin/ or data at http://localhost:7474/db/data/ ? 我们如何从Web界面(例如位于http://localhost:7474/webadmin/ Dashboard或http://localhost:7474/db/data/访问此graphDb

Please let me know in case you need any specific information to help me.. 如果您需要任何特定信息来帮助我,请告诉我。

Thanks, Nitin. 谢谢你,尼丁。

For getting started with Neo4j Embedded and the Java API see: 有关Neo4j Embedded和Java API的入门,请参阅:

http://docs.neo4j.org/chunked/milestone/tutorials-java-embedded.html http://docs.neo4j.org/chunked/milestone/tutorials-java-embedded.html

Getting correct counts of nodes and relationships: 获取正确的节点和关系数:

IteratorUtil.count(GlobalGraphOperations.at(gdb).getAllNodes())
IteratorUtil.count(GlobalGraphOperations.at(gdb).getAllRelationships())

For accessing an embedded graph database with an integrated neo4j server, see http://docs.neo4j.org/chunked/milestone/server-embedded.html 有关使用集成neo4j服务器访问嵌入式图形数据库的信息,请参见http://docs.neo4j.org/chunked/milestone/server-embedded.html

Phewww! 哎呀! Those are a lot of questions for one entry... 这些对于一个条目来说是很多问题...

To get the total number of nodes and relationships in your DB, use: 要获取数据库中节点和关系的总数,请使用:

NodeManager nodeManager = ((GraphDatabaseAPI) graphDb).getDependencyResolver().resolveDependency(
            NodeManager.class);

long currentRelationships = nodeManager.getNumberOfIdsInUse(Relationship.class);
long currentNodes = nodeManager.getNumberOfIdsInUse(Node.class);

To change the path of the graph DB, simply pass the path to the GraphDatabaseFactory().newEmbeddedDatabase method. 要更改图形数据库的路径,只需将路径传递给GraphDatabaseFactory()。newEmbeddedDatabase方法。 In the example you mentioned, you could simply set DB_PATH eg to /home/youruser/neo4j . 在您提到的示例中,您可以简单地将DB_PATH设置为/home/youruser/neo4j

To access your DB with the webadmin, download neo4j, change the org.neo4j.server.database.location property in the file conf/neo4j-server.properties and point it to the path of your DB and launch the server. 要使用Webadmin访问数据库,请下载neo4j,更改文件conf/neo4j-server.properties的org.neo4j.server.database.location属性,并将其指向数据库的路径并启动服务器。

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

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