Neo4j 跨会话查询数据
我在访问以前在 Neo4j 的嵌入式 Java 版本中创建的数据库时遇到问题。我想做的是打开一个 GraphDatabaseService,添加几百万个关系(不使用 BatchInserter,仅使用事务),然后关闭最后一个事务和连接。这看起来像:
public class startNeo4j{ …
public static void main (String[] args) {
GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "data/test/base" );
Transaction tx = graphDb.beginTx();
IndexManager index = graphDb.index();
Index<Node> userIds = index.forNodes("userIds");
RelationshipIndex follows = index.forRelationships("follows");
[这里我输入了一个非常大的csv(几百万个关系),还给出了关系和userId索引]
tx.finish();
graphDb.shutdown(); }}
然后我需要做的是打开一个新的GraphDatabaseService并访问我刚刚插入的所有数据。我检查了 Neo4j 列表,他们确认这是可能的,但没有提供任何细节。
我不想重新创建索引,但是当我尝试简单地重新打开它时,我收到一个错误,其中索引(上面的 userIds)“无法解析”。理想情况下,如果有人能大致了解第二组代码的外观,那就太好了。我的非功能性查询如下所示:
public class examineNeo4j{
public static void main (String[] args){
GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "data/test/base" );
Transaction tx = graphDb.beginTx();
IndexHits<Node> hits_final = userIds.get("userId","12");
Node testthis = hits_final.getSingle();
[或我想要运行的其他一些查询]
tx.finish();
graphDb.shutdown();}}
任何帮助将不胜感激!
I am having trouble accessing previously created databases in the embedded Java version of Neo4j. What I'd like to do is open a GraphDatabaseService, add several million relationships (not using BatchInserter, only transactions), and then shut down the last transaction and the connection. This would look something like:
public class startNeo4j{ …
public static void main (String[] args) {
GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "data/test/base" );
Transaction tx = graphDb.beginTx();
IndexManager index = graphDb.index();
Index<Node> userIds = index.forNodes("userIds");
RelationshipIndex follows = index.forRelationships("follows");
[ here I input a very large csv (several million relationships), also giving relationship and userId indices ]
tx.finish();
graphDb.shutdown(); }}
What I then need to be able to do is open a new GraphDatabaseService and access all that data I just inserted. I checked with the Neo4j list and they've confirmed that it's possible, but didn't provide any details.
I don't want to recreate the index, but when I try to simply reopen it, I get an error where the index (userIds from above) "cannot be resolved." Ideally, if someone had an outline of what the second set of code would look like that would be great. My non-functional one looks like:
public class examineNeo4j{
public static void main (String[] args){
GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "data/test/base" );
Transaction tx = graphDb.beginTx();
IndexHits<Node> hits_final = userIds.get("userId","12");
Node testthis = hits_final.getSingle();
[ or some other query that I want to run ]
tx.finish();
graphDb.shutdown();}}
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你还必须执行 tx.success();默认情况下,tx 处于“回滚”状态。
另请记住,您的交易大小不应超过 10k 次操作左右。所以请使用这样的块大小批量交易。
You also have to do tx.success(); by default a tx is in a "rollback" state.
Please keep also in mind that your tx size shouldn't exceed around 10k operations. So please batch transaction with such a block size.