Develop a Graph

From whiteboard to world stage, Neo4j works the way you think.

There are Three APIs...

Neo4j has a trio of programming interfaces, focused on different kinds of interaction.

As always, pick the right tool for the job.

Work with the Cypher language

Neo4j's Cypher language is purpose built for working with graph data. Inspired by SQL syntax, embracing pattern matching for describing paths, Cypher is the primary tool for building graph applications.

Let's use Cypher to generate the graph described in the Learn Guide. Starting with Emil:

CREATE (ee:Person { name: "Emil", from: "Sweden" }) RETURN ee;

Cypher, finding nodes

Now find the node representing Emil:

MATCH (ee:Person) WHERE ee.name = "Emil" RETURN ee;

Cypher, create nodes and relationships

CREATE clauses can create many nodes and relationships at once.

CREATE (ee:Person { name: "Emil", from: "Sweden", klout: 99 }),
(js:Person { name: "Johan", from: "Sweden", learn: "surfing" }),
(ir:Person { name: "Ian", from: "England", title: "author" }),
(rvb:Person { name: "Rik", from: "Belgium", pet: "Orval" }),
(ally:Person { name: "Allison", from: "California", hobby: "surfing" }),
(ee)-[:KNOWS {since: 2001}]->(js),(ee)-[:KNOWS {rating: 5}]->(ir),
(js)-[:KNOWS]->(ir),(js)-[:KNOWS]->(rvb),
(ir)-[:KNOWS]->(js),(ir)-[:KNOWS]->(ally),
(rvb)-[:KNOWS]->(ally);

Cypher pattern matching

Cypher uses patterns to describe how to find things in the graph. For instance, to find Emil's friends:

MATCH (ee:Person)-[:KNOWS]->(friends:Person) 
WHERE ee.name = "Emil" RETURN friends;

Cypher recommendations

Pattern matching can be used to make recommendations. Johan is learning to surf, so he may want to find a new friend who already does:

MATCH (js:Person)-[:KNOWS]->()-[:KNOWS]->(surfer:Person) 
WHERE js.name = "Johan" 
AND has(surfer.hobby) AND surfer.hobby = "surfing"
RETURN DISTINCT surfer;

Discover with REST

Once you've created a graph with Cypher, the REST interface can be useful for interactively walking the graph in a hypermedia way. This interface is also useful for checking system statistics and settings.

The web is a graph. Why not navigate a graph like browsing the web.

Customize with Plugins

Cypher is an expressive and powerful language, intended to cover the vast majority of operations. When you have specialized needs, plugins allow you to "get under the hood."

With great power comes great responsibility.

Summary

Start your application using Cypher to create and query graph data. Use the REST API to monitor the database. In special cases, consider a plugin.

Now, go get started on your own application.

Next steps:

Or, see other guides.