ExecutionFailure"未知标识符"在使用UNION时在ORDER BY中

时间:2014-04-18 14:39:21

标签: neo4j cypher

我对以下cypher查询返回的错误感到困惑:

MATCH (p1:Person)-[r_ptq]->(tq:Ticket)
WHERE tq.name IN ["music", "sports", "movie"]
RETURN distinct(p1) AS person, count(r_ptq) AS score, collect(tq.name) AS tickets
ORDER BY score DESC LIMIT 10

UNION

MATCH (t:Ticket)<-[r_ttq]-(tq:Ticket)
WHERE tq.name IN ["music", "sports", "movie"]
WITH distinct(t), sum(r_ttq.weight) AS weight
ORDER BY weight DESC LIMIT 50
MATCH (t)<--(p:Person)
RETURN distinct(p) AS person, sum(weight) AS score, collect(t.name) AS tickets
ORDER BY score DESC LIMIT 10

这将始终返回

Unknown identifier `score`.

显然是标识符&#34;得分&#34;在将查询与UNION组合时,无法识别ORDER BY指令。如果我单独运行这两个查询(在UNION之上和之下),这完全正常。另外如果我删除ORDER BY指令,它将与UNION一起使用,但这当然会改变行为。< / p>

非常感谢任何关于如何解决这个问题的指示。

我调整了上面的示例以处理console.neo4j.org

上的图表
MATCH (p1:Crew)-[r_ptq]->(tq:Crew)
WHERE tq.name IN ["Neo", "Morpheus"]
RETURN distinct(p1) AS person, count(r_ptq) AS score, collect(tq.name) AS tickets
ORDER BY score DESC
LIMIT 10
UNION
MATCH (t:Crew)<-[r_ttq]-(tq:Crew)
WHERE tq.name IN ["Neo", "Morpheus"]
WITH distinct(t), count(r_ttq) AS weight
ORDER BY weight DESC
LIMIT 50
MATCH (t)<--(p:Crew)
RETURN distinct(p) AS person, sum(weight) AS score, collect(t.name) AS tickets
ORDER BY score DESC
LIMIT 10

然后它返回 Error: org.neo4j.graphdb.NotFoundException: Unknown identifier 'weight'.

在没有UNION的情况下严格运行查询。

1 个答案:

答案 0 :(得分:0)

Cypher查询在语法上是正确的,可在Neo4j浏览器中使用。 console.neo4j.org上的控制台似乎有一些JavaScript RegEx验证,当使用WITH跟踪UNION中的标识符时会出现错误。我们将调查此错误并在控制台中修复它。

目前,请在http://www.neo4j.org/download下载Neo4j,使用Neo4j 2.0浏览器。