Neo4j:列出节点标签 [英] Neo4j: Listing node labels

查看:76
本文介绍了Neo4j:列出节点标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有 2 个层次结构.

I have 2 hierarchies in my database.

层次结构 1:

Company{name:'ABC', CompanyId:1,} <-- 类别 <-- 子类别 <-- 服务 <-- 资产 <-- 异常

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

层次结构 2:

Company{name:'XYZ', CompanyId:21,} <-- 类别 <-- 服务 <-- 资产 <-- 异常

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

在我的层次结构中查询 CompanyId 的节点标签的最佳方法是什么?我正在寻找以下格式的输出:

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:

公司 ID:1

公司类别子类别服务异常

Company Category SubCategory Service Anomaly

公司 ID:2

公司类别服务异常

谢谢.

推荐答案

假设每个公司层级链都以具有标签 Company 的公司节点开始,并且始终以具有 标签的节点开始>Anomaly 标签,您可以跟踪公司层次结构的路径并返回每个链的标签列表.

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] + " ")

这篇关于Neo4j:列出节点标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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