Neo4j

Fácil e Rápido

O que é?

NoSQL

Um banco de grafos (redes)

 

Ótimo para pontual

Ex: "Esse nó está conectado com algo?"

 

Péssimo para batch

Ex: "Essa rede está toda conectada?"

 

 

 

Instalação (Docker)

  • docker pull neo4j
  • mkdir -p neo4j/data
  • docker run --publish=7474:7474
               --publish=7687:7687
               --volume=$PWD/neo4j/data:/data
               neo4j

Web Interface

  • http://localhost:7474
  • user: neo4j
  • pass: neo4j

Instalação (Local)

  • https://neo4j.com/download/community-edition
  • untar or unzip
  • neo4j/bin/neo4j start

Instalação (AWS)

http://optimalbi.com/blog/2016/03/15/how-to-install-neo4j-on-aws-linux/

Nota: por padrão, a porta é 7474 e só possui acesso local.

Acerte o arquivo /etc/neo4j/neo4j.config

Databases

https://neo4j.com/developer/example-data/

 

What it can do?

http://ec2-54-242-58-60.compute-1.amazonaws.com:7474

"Movie Database"

user: neo4j

pass:123

(access will be removed after this session)

List Actors

match (x:Actor) return x limit 10

Actors and Movies

match (a:Actor)-[:ACTS_IN]->(m:Movie)
return a, m limit 30

Co-starring

match (a1:Actor)-[:ACTS_IN]->(m:Movie),
      (m)<-[:ACTS_IN]-(a2:Actor)
where a1.name = 'Buster Keaton'
return a1, m, a2 limit 30

6 degrees to Bacon

match (a1:Actor), (a2:Actor),
      p = shortestPath((a1)-[*..7]-(a2))
where a1.name = 'Buster Keaton' and
      a2.name = 'Kevin Bacon'
return p limit 30

Let's upload

docker pull ruliana/neo4j-spatial

docker run --publish=7474:7474
           --publish=7687:7687
           --volume=neo4j/data:/data
           ruliana/neo4j-spatial

Load CSV

load csv with headers from "https://goo.gl/3mZaGW" as line
return line
limit 10

 

 

Now, for real

call spatial.addPointLayerXY("crime-spot", "latitude", "longitude")


load csv with headers from "https://goo.gl/3mZaGW" as line
create (c:Crime {ncic: toInteger(line.ucr_ncic_code),
             latitude: toFloat(line.latitude),
            longitude: toFloat(line.longitude),
          description: line.crimedescr})
with c
call spatial.addNode("crime-spot", c) yield node
return node

Neo4j

By Ronie Uliana

Neo4j

  • 2,240