Cypher Introduction

What is Cypher?

Cypher is a query language for the Neo4j Graph Database.

  • Cypher is a declarative graph query language.
  • It is used for expressive and efficient querying, updating and administering of the Graph.
  • It is inspired by and similar to SQL.
  • It is easy to write and understand.
  • It is used to find data that matches a specific pattern.
  • Nodes are represented by parentheses.
  • Relationships are defined by square brackets.
  • Relationships in Neo4j and hence in Cypher are always directed.

A Simple Cypher Query

Example

MATCH (p :Person)-[:KNOWS]->(s:Skill {name:”Graph Databases”})
RETURN p

Example Explained

  • MATCH keyword is used to match a specific pattern in the graph.
  • RETURN keyword is used to return the values.
  • This example returns all the values of Person p who know about Graph Databases.

Example

CREATE (:Person {firstname:”Rick”, lastname:”Sanchez”})

Example Explained

  • CREATE keyword is used to create a new entry in the graph.
  • This example returns creates a new Person with first name Rick and last name Sanchez.

Neo4j Browser

Neo4j Browser provides an interactive way to access the Neo4j Graph Database. You can execute the cypher queries much like you do in a shell, by simply writing the query and pressing Enter. In addition it also provides a nice visualization of Graphs returned from the query in addition to just data in the form of rows. It is highly suggested to use Neo4j Browser to learn the Cypher Query Language. It is easy to use and has an intuitive User Interface.

Where to Practice Cypher

  • You can sign up for a Neo4j Sandbox on the cloud, which is available for up to 3 days for free, which is extendable to 10 days over here. You can then use Neo4j Browser to query the database on the cloud.
  • If however you want to use Neo4j for more than 10 days, you can download it from here and install it locally on your system. Neo4j Browser will be included with the database and will be available after installation.

A Brief History of Cypher

Cypher Query Language was created by Andrés Taylor while working for Neo4j, Inc. (formerly Neo Technology) in 2011. It was originally intended to be used with the Neo4j Graph Database, but was opened up through the openCypher project in October 2015.
Along with the openCypher project came the effort to standardize Cypher as the query language for graph processing.
Initial supporters of openCypher include: Neo Technology, Oracle, Databricks, Tableau, GraphAware, GrapheneDB, Graph Story, GraphGrid, Information Analysis Incorporated (IAI), Linkurious, Structr, ThoughtWorks and Tom Sawyer Software.