Chapter 6. Cypher: Neo4j query language
This chapter covers
- Explaining Cypher
- Executing Cypher queries
- Writing read-only Cypher queries
- Manipulating graph data using Cypher
In previous chapters we used the Neo4j Core Java API to manipulate and query graph data. This obviously required some Java skills to write and understand the implemented code. In addition, as the complexity of the queries increased, the code grew in both size and complexity, making it difficult to understand in some cases. This is where a query language comes in handy, allowing you to query and manipulate graphs using the power of expressive language structures that are also simple to read.
Neo4j’s query language is called Cypher. In this chapter we’re going to explain the nature of Cypher, demonstrate its basic syntax for graph operations, and cover some of the advanced features that can be useful in day-to-day development and maintenance of Neo4j databases.
Cypher is a declarative query language for graphs that uses graph pattern-matching as a main mechanism for graph data selection (for both read-only and mutating operations). The declarative pattern-matching nature of Cypher means that you can query the graph by describing what you need to get from it.
To explain how Cypher works, let’s take a look at Cypher in action.
Figure 6.1 shows a simple graph representing a social network.