Database Reference
In-Depth Information
Chapter 4. The power of traversals
This chapter covers
• Querying Neo4j using the Core Java API
• Traversing nodes and relationships using the Neo4j Traversal API
• Extending and customizing built-in Neo4j traversal operations
Chapter 3 introduced you to the Neo4j Core Java API and you created a graph representing
a social network of users and the movies they like. In this chapter we're going to look at
graphtraversals—apowerfulwayofqueryingthegraphdata. Graph traversal istheprocess
of visiting nodes in the graph by following the relationships between nodes in a particular
manner.
We'll demonstrate the traversal options by showing you how to solve simple traversal prob-
lems, followed by more complex ones. In this chapter you'll get more familiar with the
Neo4j Core Java API, as well as with the more advanced Neo4j Traversal Framework Java
API (or “Neo4j Traversal API” for short).
Let'sstartwiththesimplesttraversal,whichfollowsrelationshipstofinddirectneighborsof
the starting node using the Neo4j Core Java API.
4.1. Traversing using the Neo4j Core Java API
The first traversal approach we'll look at makes use of standard methods available on the
Neo4j Core Java API. We'll use the graph created in chapter 3 to perform the traversals.
The first traversal we'll look at can be described as “Starting from the node representing the
user John Johnson, find all the movies that this user has seen.” Figure 4.1 illustrates the part
of the graph we're interested in.
Search WWH ::




Custom Search