neo4j ¿cómo devolver todas las etiquetas de nodo con Cypher?


No puedo encontrar cómo devolver las etiquetas de un nodo con Cypher.

¿Alguien conoce la sintaxis de esta operación?

Author: Sovos, 2013-08-23

7 answers

Hay una función labels(node) que puede devolver todas las etiquetas de un nodo.

 44
Author: Lisa Li,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-23 12:10:31

Para obtener todas las etiquetas de nodo distintas:

MATCH (n) RETURN distinct labels(n)

Para obtener el número de nodos para cada etiqueta:

MATCH (n) RETURN distinct labels(n), count(*)
 55
Author: petra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-14 22:49:45

Si desea todas las etiquetas individuales (no las combinaciones) siempre puede ampliar las respuestas:

MATCH (n)
WITH DISTINCT labels(n) AS labels
UNWIND labels AS label
RETURN DISTINCT label
ORDER BY label
 15
Author: ErnestoE,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-14 10:38:07

Neo4j 3.0 ha introducido el procedimiento db.labels() que devuelve todas las etiquetas disponibles en la base de datos. Uso:

call db.labels();
 7
Author: Bruno Peres,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-18 12:45:18
 START n=node(*) RETURN labels(n)
 5
Author: gaurav.singharoy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-02 16:34:32

Si está utilizando la API de Java, puede obtener rápidamente un iterador de todos los Labels en la base de datos de la siguiente manera:

GraphDatabaseService db = (new GraphDatabaseFactory()).newEmbeddedDatabase(pathToDatabase);
ResourceIterable<Label> labs = GlobalGraphOperations.at(db).getAllLabels();
 3
Author: Ken Williams,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-06-29 20:10:34

Si desea obtener las etiquetas de un nodo especificado, use labels(node); Si solo desea obtener todas las etiquetas de nodo en neo4j, use esta función en su lugar: call db.labels;, nunca use esta consulta: MATCH n RETURN DISTINCT LABELS(n). Hará un escaneo completo de la tabla, que es muy, muy lento..

 2
Author: arganzheng,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-09 03:25:50