Skip to content

Instantly share code, notes, and snippets.

@JamesHagerman
Last active July 29, 2019 15:32
Show Gist options
  • Select an option

  • Save JamesHagerman/a4ff74b0c7a405088ccf8664f0620af4 to your computer and use it in GitHub Desktop.

Select an option

Save JamesHagerman/a4ff74b0c7a405088ccf8664f0620af4 to your computer and use it in GitHub Desktop.
Just some notes on standing neo4j up on docker and building graphs

Neo4j notes

Neo4j is a true graph database. Really, a property graph, but it's better than hacking graph data into other databases.

Start an instance of neo4j in docker

Note: This places the data in ~/someProject/data. If you want it somewhere else, you'll have to change this command.

docker run \
    --publish=7474:7474 --publish=7687:7687 \
    --volume=$HOME/someProject/data:/data \
    --name someProject-neo4j \
    neo4j

Start neo4j in a docker file WITH APOC PLUGIN

NOTE: This also disables auth!!!

docker run \
    --publish=7474:7474 --publish=7687:7687 \
    -e NEO4J_AUTH=none \
    --volume=$PWD/hobbygraph/data:/data \
    --volume=$PWD/plugins:/plugins \
    --name hobbygraph-neo4j \
    -e NEO4J_apoc_export_file_enabled=true \
    -e NEO4J_apoc_import_file_enabled=true \
    -e NEO4J_apoc_import_file_use__neo4j__config=true \
    neo4j

Using a docker-compose.yml file

version: '2'

services:
  hobbygraph:
    image: neo4j
    ports:
      - 7474:7474
      - 7687:7687
    volumes:
      - ./hobbygraph-data:/data
      - ./plugins:/plugins
    restart: unless-stopped
    environment:
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true
      - NEO4J_AUTH=none

Use cypher-shell and APOC to dump a Cypher file of your data:

First, you need to install APOC into the Docker container by mounting a plugins/ volume into the neo4j docker container as described here:

(https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_using_apoc_with_neo4j_docker_image)[https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_using_apoc_with_neo4j_docker_image]

OR maybe you could actually make your own Docker image that just downloads the file into the Docker image on it's own...?

Remember, cypherFormat can be create, updateAll, addStructure, or updateStructure. They are defined here:

(https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_export_to_cypher_script)[https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_export_to_cypher_script]

docker exec -it hobbygraph-neo4j bash
cypher-shell
CALL apoc.export.cypher.all("/data/hobby-graph.cypher", {format : "cypher-shell", cypherFormat: "create"});

Access Neo4j through the browser

Use this URL to access the Neo4j developer interface: (http://0.0.0.0:7474/browser/)[http://0.0.0.0:7474/browser/]

By default, the username and password is: neo4j, neo4j and you'll be asked to change your password when you first log in.

Useful Scripts

After you've logged in, you should probably go through the Neo4j documentation a bit. When you start understanding the point, the following scripts should help you start building graphs.

Add Node:

CREATE (:Project {name:"Decode YS1 Packets"})

Add Edge between two nodes:

MATCH (start:Project {name:"LayerOne 2018 Demo Party Entry"})
MATCH (end:Equipment {name:"1UP badge"})
CREATE (start)-[r:HARDWARE]->(end)
RETURN r

Find node using internal id:

MATCH (s)
WHERE ID(s) = 126
RETURN s

Find, Detach, and Delete a connected node based on internal id:

MATCH (s)
WHERE ID(s) = 60
DETACH
DELETE s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment