From whiteboard to world stage, Neo4j works the way you think.
Neo4j has a trio of programming interfaces, focused on different kinds of interaction.
As always, pick the right tool for the job.
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;
CREATE
clause to create data()
parenthesis to indicate a node:Person
to label the node{}
brackets to add properties to the nodeRETURN
clause indicates what data to returnNow find the node representing Emil:
MATCH (ee:Person) WHERE ee.name = "Emil" RETURN ee;
MATCH
clause specify what to look for(ee:Person)
to find all nodes labeled PersonWHERE
clause to filter the resultsee.name = "Emil"
to filter nodes where the property 'name' is 'Emil'RETURN
clause requests particular results
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 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;
MATCH
clause to describe the pattern to look for, from known Nodes to found Nodes(ee:Person)
starts the pattern with Emil-[:KNOWS]->
matches outgoing "KNOWS" relationships(friends:Person)
will be bound to Emil's friendsPattern 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;
()
empty parenthesis to ignore these nodeshas(surfer.hobby)
to only look for persons with a hobbyDISTINCT
because there may be multiple paths to a friendsurfer
will contain Allison, a friend of a friend who surfsOnce 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.
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.
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.