Database Reference
In-Depth Information
Chapter 4
Querying
Neo4j includes a powerful and expressive query language called Cypher . Cypher is a declarative query language that
provides for very efficient reading and writing of data within Neo4j. This chapter starts with some background on
Cypher and then moves to an overview of some basic Cypher operations.
If you are familiar with Structured Query Language (SQL), then you will notice some similarities between it and
the Cypher language. The section “SQL to Cypher” describes some of those similarities and compares statements in
SQL and Cypher.
This chapter goes on to discuss read statements, more advanced statements that exploit the benefits of various
functions within Cypher, some elementary write statements, and some more advanced write operations. The chapter
closes with a look at proper removal clauses and functions.
Cypher Basics
Cypher was created to be optimally accessible and simple to use for the widest possible array of users: software
developers, business analysts, and technical architects. The most common query operations in Cypher are meant
to focus on what needs to be retrieved and not on how it is retrieved. This section covers concepts that are
important to understand as you begin to use Cypher—whether through REST, within the web UI, or embedded
within your applications.
To get started with the Cypher and follow along with the examples in this chapter, you will need to have a running
instance of Neo4j. To quickly setup a Neo4j server instance, go to http://www.graphstory.com/practicalneo4j .
You will be provided with your own trial instance, a knowledge base, and email support from Graph Story.
Note
Cypher shares some traits with SQL and uses similar keyword statements to run operations inside the Neo4j
database. In many cases, a query is made up of several clauses to achieve an end result. As an example of Cypher's
ability to focus on what is retrieved rather than on how the data is retrieved, a query may start by retrieving a large set of
nodes from the graph and then ultimately return a subcollection of the large set—sometimes referred to as subgraph .
Transactions
Beyond its superior speed and scaling abilities, another significant advantage of using Neo4j for data operations is its
transactional capability. Any Cypher query that modifies the graph will run in a transaction and will always either fully
succeed on each query or not succeed at all.
 
 
Search WWH ::




Custom Search