In Cypher, a pattern for a MATCH clause consists of three parts as you can see in the image below.
Before Neo4J 2.*, a query must start with the START clause by specifying one or more starting points. Generally, we use the RootNode as the starting point given the node id is always zero. The RootNode and START clause concepts have a limitation of forcing us to specify multiple start points early on in the query or forcing the RootNode to be passed on in all the WITH clauses to allow the query to navigate off another path down the track.
In Neo4J 2.*, the smallest pattern for a MATCH clause consists only of a single part, the source identifier. This is due to allowing filters on identifiers in MATCH clauses. The sections below will discuss each filter in detail.
When you create a node, you can tag it with one or more labels. The labels are a way of grouping multiple nodes together, which in turn allows a single node to be part of multiple groups.
The image below displays a graph of an agency with two people. One person has the role of a Client and Carer whereas the other is only a Carer. Labelling nodes simplifies the schema dramatically, as you can see in the image, and also simplifies the queries and allows the queries to be more flexible in its construction.
Because the labels are indexed, you can simply fetch all the nodes belonging to a given label in a single MATCH clause, see Query 2 in the image above. That MATCH clause consists of only one part of the pattern, the source identifier. The query no longer requires a START clause to specify a starting point. Each identifier filtered by a label becomes the start point for a query.
The image below displays two queries that run at the same cost and return the same result. The only difference is the writing style. The second query uses the newly introduced identifier filters in the match clause. The red underlined segment is the earlier discussed label filter and the yellow underlined segment represents the property filter.
As you can see in the above image, property filters are simple WHERE clause statements written in-line within the MATCH clause. They are applied on the identifiers to restrict its results and to keep the syntax and scope small. The property filter can only perform exact matches on the properties. For conditional matches, such as greater than and regular expressions, we need to resort to the normal WHERE clause.