Neo4j: Listing node labels

天涯浪子 提交于 2019-12-13 06:39:39

问题


I have 2 hierarchies in my database.

Hierarchy 1:

Company{name:'ABC', CompanyId:1,} <-- Category <-- SubCategory <-- Service <-- Asset <-- Anomaly

Hierarchy 2:

Company{name:'XYZ', CompanyId:21,} <-- Category <-- Service <-- Asset <-- Anomaly

What is the best way to query node labels in my hierarchy for a CompanyId? I am looking for an output in the following format:

CompanyId:1

Company Category SubCategory Service Anomaly

CompanyId:2

Company Category Service Anomaly

Thanks.


回答1:


Assuming that every company hierarchy chain begins with a company node that has the label Company and always and with an node with the Anomaly label, you could go after paths of the company hierarchy and return the list of labels for each chain.

match p=(:Company)<-[*]-(:Anomaly)
with head(nodes(p)) as Company, p
return Company.CompanyId, reduce(labels = "", n IN nodes(p) | labels + labels(n)[0] + " ")


来源:https://stackoverflow.com/questions/28681685/neo4j-listing-node-labels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!