Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding label names in simple Neo4j Query

Tags:

Usually I can find everything I need already on SO but not this time. I'm looking for a very simple way to exclude labels, for example (pseudo code):

match (n) where n not in (Label1, Label2) return n 

Sorry about crappy query. In short I have labels x,y,z and I want to return all of them apart from z.

Thnx!

like image 801
Ed Baker Avatar asked Sep 28 '15 06:09

Ed Baker


People also ask

What is label name in Neo4j?

Label is a name or identifier to a Node or a Relationship in Neo4j Database. We can say this Label name to a Relationship as "Relationship Type". We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node.

Can a node have more than one label in Neo4j?

Create a node with multiple labels. To add labels when creating a node, use the syntax below. In this case, we add two labels.

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) . It will do a full table scan, which is very very slow..


1 Answers

This should do it:

MATCH (n) WHERE NOT n:Label1 AND NOT n:Label2 RETURN n; 
like image 190
Oskar Hane Avatar answered Sep 19 '22 21:09

Oskar Hane