Skip to content

Instantly share code, notes, and snippets.

View nawroth's full-sized avatar

Anders Nawroth nawroth

View GitHub Profile

Neo4j GraphGist

Neo4j GraphGists are a way to share documents including Cypher queries. The queries can be executed in an online console. GraphGists can be used to share examples or ideas or outline a question you have.

See also the GraphGist Collection and check out the GraphGist Challenge!

You create a GraphGist by creating a GitHub Gist in AsciiDoc and enter the URL to it in the form on this page. The GraphGist is just as private as the GitHub Gist you created.

DocGist Example

DocGist is a tool that renders AsciiDoc documents fetched from GitHub gists or other sources. The rendering is performed in the browser using the asciidoctor.js library. The original use case for this was http://gist.neo4j.org/ which has additional features to create examples for the Neo4j graph database.

How To Use

  • Create/locate a gist on GitHub (or use a file in Dropbox).

    • Write text using AsciiDoc syntax in it.

How to create a GraphGist

You create a GraphGist by creating a GitHub Gist in AsciiDoc and enter the URL to it in the form on this page. Alternatively, you can put an AsciiDoc document in Dropbox and enter the public URL in the form.

This GraphGist shows the basics of using AsciiDoc syntax and a few additions for GraphGists. The additions are entered as comments on their own line. They are: //console for a query console; //hide, //setup and //output to configure a query; //graph and //table to visualize queries and show a result table.

Click on the Page Source button in the menu to see the source for this GraphGist.

= The Neo4j GraphGist Console =
This is a sample GraphGist explaining some of the base concepts of sharing graphs using http://docs.neo4j.org/chunked/milestone/cypher-query-lang.html[the Cypher query language].
[source,cypher]
----
CREATE ({name:'you'})-[:SEE]->({name:'This GraphGist'})-[:FORK_ON_GITHUB]->(your_gistfile{name:'Your Gist'})
CREATE (your_gistfile)-[:INSERT_ID_HERE]->({name:'Your GraphGist'})
----

Movie Database

Our example graph consists of movies with title and year and actors with a name. Actors have ACTS_IN relationships to movies, which represents the role they played. This relationship also has a role attribute.

cineasts

We’ll go with three movies and three actors:

@nawroth
nawroth / attributes.adoc
Last active December 31, 2015 06:19
attributes test

Testing document attributes

{my-attribute}

{someattribute}

Using labels

Labels is a convenient way to group nodes together. They are used to enhance queries, define constraints and indexes.

The following will give an example of how to use labels. Let’s start out adding a constraint — in this case we decided that all Movie nodes should have a unique title.

this is the title
MATCH (n) RETURN n
@nawroth
nawroth / case.adoc
Last active December 24, 2015 15:58

The case for CASE

This is how you might model Premier League managers tenures at different clubs in Neo4j:

managers tiff

The date modeling is based on an approach described in more detail in Return partly shared path ranges.

Finding Paths

Our example graph consists of movies with title and year and actors with a name. Actors have ACTS_IN relationships to movies, which represents the role they played. This relationship also has a role attribute.

We queried and updated the data so far, now let’s find interesting constellations, a.k.a. paths.