简体   繁体   English

neo4j如何用Cypher返回所有节点标签?

[英]neo4j how to return all node labels with Cypher?

I can't find how to return a node labels with Cypher. 我找不到如何用Cypher返回节点标签。

Anybody knows the syntax for this operation? 有谁知道这个操作的语法?

To get all distinct node labels: 要获取所有不同的节点标签:

MATCH (n) RETURN distinct labels(n)

To get the node count for each label: 要获取每个标签的节点数:

MATCH (n) RETURN distinct labels(n), count(*)

有一个函数标签(节点)可以返回节点的所有标签。

If you want all the individual labels (not the combinations) you can always expand on the answers: 如果您想要所有单个标签(而不是组合),您可以随时扩展答案:

MATCH (n)
WITH DISTINCT labels(n) AS labels
UNWIND labels AS label
RETURN DISTINCT label
ORDER BY label

Neo4j 3.0 has introduced the procedure db.labels() witch return all available labels in the database. Neo4j 3.0引入了db.labels()过程,返回数据库中所有可用的标签。 Use: 使用:

call db.labels();
 START n=node(*) RETURN labels(n)

If you're using the Java API, you can quickly get an iterator of all the Label s in the database like so: 如果您正在使用Java API,则可以快速获取数据库中所有Label的迭代器,如下所示:

GraphDatabaseService db = (new GraphDatabaseFactory()).newEmbeddedDatabase(pathToDatabase);
ResourceIterable<Label> labs = GlobalGraphOperations.at(db).getAllLabels();

If you want to get the labels of a specify node, then use labels(node) ; 如果要获取指定节点的标签,则使用labels(node) ; If you only want to get all node labels in neo4j, then use this function instead: call db.labels; 如果您只想获取neo4j中的所有节点标签,请改用此函数: call db.labels; , never ever use this query: MATCH n RETURN DISTINCT LABELS(n) . ,永远不要使用此查询: MATCH n RETURN DISTINCT LABELS(n) It will do a full table scan, which is very very slow.. 它会进行全表扫描,这非常慢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM