使用集合嵌套cypher查询

时间:2015-02-02 11:02:24

标签: neo4j

我在Neo4J中有一个链接的事件列表,其中包含:NEXT关系。我可以通过以下方式检索接下来3个事件的聚合集合:

MATCH(e:Event {eventType:“123”}), path =(e) - [:NEXT * 3] - >() RETURN [节点IN节点(路径)| node.eventType] as et,count(*)as count ORDER BY count DESC LIMIT 10

我通过以下方式连接EventDetail节点中的事件类型的文本描述:

MATCH(e:Event {eventType:“123”}) - [:DETAILS] - >(ed:EventDetails)RETURN ed.description LIMIT 1

有没有办法嵌套这些并从第一个查询中获取ed.description属性?感谢。

2 个答案:

答案 0 :(得分:1)

这应该在单个查询中返回每个Event节点的描述{/ 1}}。

eventType: '123'

调整上述查询以获取路径中每个节点的返回事件详细信息,而不仅仅是第一个节点。

// if every event has EventDetails then match up front
MATCH (e:Event {eventType:”123”})-[:DETAILS]->(ed:EventDetails)
// you can use the with clause to pass the nodes to teh next section where you match the path
WITH e, ed
MATCH path=e-[:NEXT*3]->() 
RETURN [node IN nodes(path) | node.eventType] as et
, ed.description
,count(*) as count 
ORDER BY count DESC LIMIT 10

答案 1 :(得分:0)

也许是这样的:

MATCH (e:Event {eventType:”123”}), path = (e)-[:NEXT*3]->() 
WITH [node IN nodes(path) | id(node)] as et, count(*) as count 
MATCH (e)-[:DETAILS]->(ed) WHERE id(e) IN et
RETURN et, COLECT(ed), count 
ORDER BY count DESC LIMIT 10