Database Reference
In-Depth Information
Listing 4-21. A Query with USING INDEX to Explicitly Specify an Index to Be Searched
MATCH (u:User)
USING INDEX u:USER(username)
WHERE u.username = 'greg'
RETURN u
If your query could achieve better performance by scanning all the nodes via a LABEL, use USING SCAN, as
shown in Listing 4-22.
Listing 4-22. A Query with USING SCAN to Explicitly Specify an LABEL Type and the Filtering on a Property
MATCH (u:User)
USING SCAN u:USER
WHERE u.username = 'greg'
RETURN u
Reading
The preceding sections have covered a number of Cypher queries that read from the graph. This section digs a little
deeper into a few of the reading clauses that will likely make up the majority of the read statements in your Neo4j
applications.
Match
The MATCH clause is the primary clause for retrieving data from your graphs and specifying the starting points in
your queries. Listings 4-23 through 4-26 exemplify ways that MATCH is used in combination with other clauses to
return data.
Listing 4-23. MATCH Using a Label, Returning All Nodes of Type User
MATCH (u:User )
RETURN u
Listing 4-24. MATCH Using a Label and Property and Specifying a Relationship Type or Direction
MATCH (a:User {username:"greg"})--(b)
RETURN a,b
Listing 4-25. MATCH Using a Label and Property and a Label on the Other Node but No Specific Relationship
Type or Direction
MATCH (u1:User {username: "greg"} )--(u2:User)
RETURN u1, u2
Listing 4-26. MATCH Using a Label and Property and Two Relationship Types
MATCH (u:User {userId:1} )-[:CURRENT|FAVORITE]-(s)
RETURN u,s
 
Search WWH ::




Custom Search