4.4. Where

4.4.1. Boolean operations
4.4.2. Filter on node property
4.4.3. Regular expressions
4.4.4. Filtering on relationship type
4.4.5. Property exists

If you need filtering apart from the pattern of the data that you are looking for, you can add clauses in the where part of the query.

4.4.1. Boolean operations

You can use the expected boolean operators AND and OR, and also the boolean function NOT().

Query

start n=(2, 1) where (n.age < 30 and n.name = "Tobias") or not(n.name = "Tobias")  return n

The node.

Result

 +-----------------------------------------------+
 | n                                             |
 +-----------------------------------------------+
 | Node[2]{name->"Andres",age->36,belt->"white"} |
 | Node[1]{name->"Tobias",age->25}               |
 +-----------------------------------------------+
 2 rows, 1 ms

4.4.2. Filter on node property

To filter on a property, write your clause after the WHERE keyword.

Query

start n=(2, 1) where n.age < 30 return n

The node.

Result

 +---------------------------------+
 | n                               |
 +---------------------------------+
 | Node[1]{name->"Tobias",age->25} |
 +---------------------------------+
 1 rows, 3 ms

4.4.3. Regular expressions

You can match on regular expressions by using =~ /regexp/, like this:

Query

start n=(2, 1) where n.name =~ /Tob.*/ return n

The node named Tobias.

Result

 +---------------------------------+
 | n                               |
 +---------------------------------+
 | Node[1]{name->"Tobias",age->25} |
 +---------------------------------+
 1 rows, 1 ms

4.4.4. Filtering on relationship type

You can put the exact relationship type in the MATCH pattern, but sometimes you want to be able to do more advanced filtering on the type. You can use the special property TYPE to compare the type with something else. In this example, the query does a regular expression comparison with the name of the relationship type.

Query

start n=(2) match (n)-[r]->() where r~TYPE =~ /K.*/ return r

The relationship that has a type whose name starts with K.

Result

 +--------------+
 | r            |
 +--------------+
 | :KNOWS[0] {} |
 +--------------+
 1 rows, 0 ms

4.4.5. Property exists

To only include nodes/relationships that have a property, just write out the identifier and the property you expect it to have.

Query

start n=(2, 1) where n.belt return n

The node named Andres.

Result

 +-----------------------------------------------+
 | n                                             |
 +-----------------------------------------------+
 | Node[2]{name->"Andres",age->36,belt->"white"} |
 +-----------------------------------------------+
 1 rows, 1 ms