使用 REST GraphDb 时 Cypher neo4j 结果缓慢

发布于 2024-12-17 07:38:30 字数 794 浏览 1 评论 0原文

我正在使用 neo4j-rest-graphdb,刚刚尝试使用 Cypher 来获取简单的 Node 结果。

CypherParser parser = new CypherParser();
ExecutionEngine engine = new ExecutionEngine(graphDbService);

Query query = parser.parse( "START referenceNode = node (0) " +
                            "MATCH referenceNode-[PRODUCTS_REFERENCE]->products-[PRODUCT]->product " +
                            "RETURN product.productName " +
                            "ORDER BY product.productId " +
                            "SKIP 20"
                            "LIMIT 10");
 ExecutionResult result = engine.execute( query );

 Iterator<Map<String, Object>> iterator = result.javaIterator();

迭代结果的最佳实践是什么?最后一行导致我的服务挂起约 6 秒。如果最后没有迭代器,应用程序会非常快速。我还尝试了 webadmin 密码终端,结果在 50 毫秒内获取。我做错了什么吗?

I am working with the neo4j-rest-graphdb an just tried to use Cypher for fetching a simple Node result.

CypherParser parser = new CypherParser();
ExecutionEngine engine = new ExecutionEngine(graphDbService);

Query query = parser.parse( "START referenceNode = node (0) " +
                            "MATCH referenceNode-[PRODUCTS_REFERENCE]->products-[PRODUCT]->product " +
                            "RETURN product.productName " +
                            "ORDER BY product.productId " +
                            "SKIP 20"
                            "LIMIT 10");
 ExecutionResult result = engine.execute( query );

 Iterator<Map<String, Object>> iterator = result.javaIterator();

What is the best practise to iterate through the result? The last line causes my service to hang for ~6 sec. Without the iterator at the end the application is quiet fast. I also tried the webadmin cypher terminal, the results are fetched within 50ms. Am i doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东风软 2024-12-24 07:38:30

在你的情况下,所有的密码操作(图形匹配、过滤等都会通过网络进行,这非常繁琐且缓慢),你不希望这样!

neo4j-rest-graphdb 支持远程执行开箱即用的 cypher:

只需执行此操作即可 测试用例

    RestCypherQueryEngine queryEngine = new RestCypherQueryEngine(restGraphDatabase.getRestAPI());      
    final String queryString = "start n=node({reference}) return n";
    Map params = MapUtil.map("reference",0);
    final Node result = (Node) queryEngine.query(queryString, params).to(Node.class).single();
    assertEquals(restGraphDatabase.getReferenceNode(), result);

In your case all the cypher operations (graph-matching, filtering etc. would go over the wire which is awfully chatty and slow) you don't want that !

The neo4j-rest-graphdb supports remote execution of cypher out of the box:

Just do, something like shown in this testcase:

    RestCypherQueryEngine queryEngine = new RestCypherQueryEngine(restGraphDatabase.getRestAPI());      
    final String queryString = "start n=node({reference}) return n";
    Map params = MapUtil.map("reference",0);
    final Node result = (Node) queryEngine.query(queryString, params).to(Node.class).single();
    assertEquals(restGraphDatabase.getReferenceNode(), result);
浅沫记忆 2024-12-24 07:38:30

如果我理解正确的话,graphDbService 是一个 REST 图形数据库,对吗?

如果您想在服务器上使用 Cypher,则应该使用 CypherPlugin。看这里:http://docs.neo4j.org/chunked/snapshot/cypher- plugin.html

我希望这有帮助,

安德烈斯

If I understood you correctly, graphDbService is a REST graph database, correct?

If you want to use Cypher on the Server, you should instead use the CypherPlugin. Look here: http://docs.neo4j.org/chunked/snapshot/cypher-plugin.html

I hope this helps,

Andrés

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文