如何在Neo4j Cypher中提供多个查询? [英] How do I provide multiple queries in Neo4j Cypher?

查看:962
本文介绍了如何在Neo4j Cypher中提供多个查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在第二个查询中使用第一个查询的结果.我不确定如何在Cypher中执行此操作?

I want to use the results from the first query in the second query. I am not sure how to do this in Cypher?

当前代码,

START user1=node:USER_INDEX(USER_INDEX = "userA") 
MATCH user1-[r1:ACCESSED]->docid1<-[r2:ACCESSED]-user2, user2-[r3:ACCESSED]->docid2 
WHERE r2.Topic=r3.Topic 
RETURN distinct docid2.Label;

我想在WHERE子句中检查相同的docid2节点集的不同条件,并根据日期字段累积结果并执行排序. 我无法在同一笔交易中提供多个匹配项并返回. 那就是当我试图拥有两个不同的密码脚本并将它们组合到第三个查询中时.密码有可能吗? 还是有编写自定义函数并调用它们的选项? 我们是否存储了诸如存储的Gremlin脚本之类的Cypher脚本?

I want to have different conditions checked in the WHERE clause for the same docid2 set of nodes and accumulate the results and perform order by based on a date field. I am not able to provide multiple match and return within the same transaction. That is when I am trying to have two different cypher scripts and combine them in a third query. Is this possible in cypher? Or is there any option to write custom functions and invoke them? Do we have stored Cypher scripts like Stored Gremlin scripts?

推荐答案

正如Michael在评论中提到的,您可以使用"with"语句将结果流式化为其他语句.不幸的是,您不能在"where"子句之后开始另一条语句.多个return语句是不合逻辑的,但是您可以在单个查询中执行多项操作,例如:

As Michael mentioned in the comment, you can use the "with" statement to stream result into further statements. Unfortunately, you can't start another statement after the "where" clause. Multiple return statements would be kind of illogical, but you can do multiple things in a single query e.g.:

START x=node:node_auto_index(key="x")
with count(x) as exists
start y=node:node_auto_index(key="y")
where exists = 0
create (n {key:"y"})<-[:rel]-y
return n, y

这将检查"x"节点是否存在,如果不存在,请继续创建它并添加几个参数.

This would check if the "x" node exists and if it doesn't, proceed to create it and add a couple of parameters.

如果您希望对结果集做更复杂的事情,最好的选择是批处理请求或Java API ...

If you wish to do more sophisticated things on result sets, your best options are either batch requests or the Java API...

这篇关于如何在Neo4j Cypher中提供多个查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆