Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match nodes without labels

Tags:

neo4j

cypher

How to write a CYPHER query that returns only those nodes that do not have labels attached to them? I tried:

match (n:) return n

Invalid input ')': expected whitespace or a label name (line 1, column 10) "match (n:) return n" ^

like image 742
Daniel Krizian Avatar asked Jun 16 '14 15:06

Daniel Krizian


People also ask

What does match do in Cypher?

Introduction. The MATCH clause allows you to specify the patterns Neo4j will search for in the database. This is the primary way of getting data into the current set of bindings. It is worth reading up more on the specification of the patterns themselves in Patterns.

How do you show all nodes and relationships in Neo4j?

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.

How do you create a relationship between two nodes in Neo4j?

To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.

What is the syntax for getting all the nodes under specific label in Neo4j?

If you want to get the labels of a specify node, then use labels(node) ; If you only want to get all node labels in neo4j, then use this function instead: call db. labels; , never ever use this query: MATCH n RETURN DISTINCT LABELS(n) .


1 Answers

In Neo4j < 2.3:

MATCH n
WHERE length(labels(n)) = 0
RETURN n

In Neo4j >= 2.3:

MATCH (n)
WHERE size(labels(n)) = 0
RETURN n
like image 128
Nicole White Avatar answered Oct 08 '22 10:10

Nicole White