Neo4j: Unterschied zwischen den Versionen

aus www.kruedewagen.de, Homepage von Ralf und Judith Krüdewagen (Kruedewagen)
Zur Navigation springen Zur Suche springen
(20 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
Auf dieser Seite befasse ich mich mit der Graph-Datenbank '''Neo4j'''. Ich habe angefangen, mich darin einzuarbeiten.
Auf dieser Seite befasse ich mich mit der Graph-Datenbank '''Neo4j'''.


== Allgemein ==
== Allgemein ==
Zeile 16: Zeile 16:
=== Artikel ===
=== Artikel ===
*siehe iX 02/11 S.130
*siehe iX 02/11 S.130
*Vergleich von fünf Graphdatenbanken: siehe LM 04/12 S.22
*siehe [[PHP Magazin]] 04/13 S.26
*siehe [[PHP Magazin]] 04/13 S.26
*Neo4j mit Perl (mit Neo4j Grundlagen): siehe [[LM]] 06/14 S.102
*[http://neo4j.com/blog/graph-commons-network-mapping/ Meet Graph Commons: Network Mapping For Everyone] (neo4j.com),
**http://graphcommons.com
**"Graph Commons is a collaborative 'network mapping' platform and a knowledge base of relationships"
*[http://neo4j.com/blog/rdbms-graph-database-deployment-strategies/ 3 RDBMS & Graph Database Deployment Strategies]
*[https://neo4j.com/blog/streaming-graphs-combining-kafka-neo4j/ Streaming Graphs: Combining Kafka and Neo4j]
*[https://neo4j.com/blog/graph-databases-for-beginners-wait-what-do-you-mean-by-graph/ Graph Databases for Beginners]
*[https://neo4j.com/blog/neo4j-graphql-iam-graphconnect-nyc Using GraphQL for Digital Identity & Access Management]
*[https://neo4j.com/blog/machine-learning-algorithms/ Machine Learning Algorithms]
=== GraphGist ===
*http://graphgist.neo4j.com
*http://neo4j.com/graphgists/
*[http://blog.armbruster-it.de/2013/11/running-neo4j-graphgists-locally-with-docker-io/ running Neo4j graphgists locally with docker.io]


== Dokumentation ==
== Dokumentation ==
Zeile 33: Zeile 48:
Videos:
Videos:
*Webinars: http://watch.neo4j.org
*Webinars: http://watch.neo4j.org
*YouTube Channel: http://www.youtube.com/neo4j
*[https://www.youtube.com/watch?v=78r0MgH0u0w Tips and Tricks for Graph Data Modeling]
*[https://www.youtube.com/watch?v=78r0MgH0u0w Tips and Tricks for Graph Data Modeling]
*[https://www.youtube.com/watch?v=Hs4O17kjQXA Relational to Graph Data Modeling] - Tipps zum Überführen eines SQL- in ein Neo4j-Modell
*[https://www.youtube.com/watch?v=Hs4O17kjQXA Relational to Graph Data Modeling] - Tipps zum Überführen eines SQL- in ein Neo4j-Modell
*[https://www.youtube.com/watch?v=OApN-I7k44c Fraud Detection with Neo4j], [http://de.slideshare.net/neo4j/fraud-detection-with-neo4j Slides dazu]


== Entwicklung ==
== Entwicklung ==
Zeile 43: Zeile 60:
*https://github.com/jakewins/Neo4j.php
*https://github.com/jakewins/Neo4j.php


Visualisierung:
===Visualisierung===
*http://www.neo4j.org/develop/visualize
*http://www.neo4j.org/develop/visualize
*http://neo4j.com/blog/graph-this-rendering-your-graph-with-graphviz/
*http://neo4j.com/blog/graph-this-rendering-your-graph-with-graphviz/
Zeile 50: Zeile 67:
**Daten für Suche aufbereiten: [http://documentcloud.github.io/visualsearch/ VisualSearch.js] (siehe [http://shop.heise.de/ix-developer-datenbanken-2015 iX Big Data] S.76)
**Daten für Suche aufbereiten: [http://documentcloud.github.io/visualsearch/ VisualSearch.js] (siehe [http://shop.heise.de/ix-developer-datenbanken-2015 iX Big Data] S.76)
**Graph query builder: [http://www.popotojs.com popoto.js] (siehe [http://shop.heise.de/ix-developer-datenbanken-2015 iX Big Data] S.76)
**Graph query builder: [http://www.popotojs.com popoto.js] (siehe [http://shop.heise.de/ix-developer-datenbanken-2015 iX Big Data] S.76)
*[http://neo4j.com/developer/r/ Neo4j for R Developers and Data Scientists]
*[http://linkurio.us Linkurious]


== Installation ==
== Installation ==
=== User und Rechte ===
Wrapper-User im System einrichten und in '''conf/neo4j-wrapper.conf''' konfigurieren:
wrapper.user=neo4j
Die Verzeichnisse '''conf''' und '''data''' sollten spezielle Rechte bzw. Eigentümer besitzen:
<pre>
# ls -la
total 304
drwxr-xr-x  8 root  root    4096 Okt 16 23:20 .
drwxr-xr-x 15 root  root    4096 Nov 18 13:51 ..
drwxr-xr-x  3 root  root    4096 Nov 18 13:51 bin
-rw-r--r--  1 root  root  93430 Okt 16 23:20 CHANGES.txt
drwxr-xr-x  3 neo4j neo4j  4096 Nov 18 13:53 conf
drwxr-xr-x  6 neo4j neo4j  4096 Nov 18 13:53 data
drwxr-xr-x  2 root  root    4096 Nov 18 13:51 lib
-rw-r--r--  1 root  root  125005 Okt 16 23:20 LICENSES.txt
-rw-r--r--  1 root  root  36045 Okt 16 23:20 LICENSE.txt
-rw-r--r--  1 root  root    5959 Okt 16 23:20 NOTICE.txt
drwxr-xr-x  2 root  root    4096 Nov 18 13:51 plugins
-rw-r--r--  1 root  root    1569 Okt 16 23:20 README.txt
drwxr-xr-x  4 root  root    4096 Nov 18 13:51 system
-rw-r--r--  1 root  root    4318 Okt 17 01:21 UPGRADE.txt
</pre>
=== Boot Script ===
Siehe offizielle Anleitung.
=== Authentifizierung ===
=== Authentifizierung ===
Standard:
Standard:
Zeile 66: Zeile 112:


== Tipps und Tricks ==
== Tipps und Tricks ==
=== Allgemein ===
*[http://neo4j.com/blog/8-tips-succeeding-with-neo4j/ 8 Solid Tips for Succeeding with Neo4j] (neo4j.com)
*Setup des Server (Ports):
curl localhost:7474
=== Cypher ===
=== Cypher ===
==== Create nodes and relations ====
==== Create nodes and relations ====
Mensch ist Label. m1 und m2 sind "Variablen", die später im Cypher-Script genutzt werden können.
Mensch ist Label. m1 und m2 sind "Variablen", die später im Cypher-Script genutzt werden können.
Zeile 124: Zeile 174:
==== Getting started ====
==== Getting started ====
  :play welcome
  :play welcome
:play start
:play sysinfo


==== Diverses ====
==== Diverses ====
Zeile 183: Zeile 235:


== Anwendungen ==
== Anwendungen ==
=== Tools ===
*https://structr.org
*https://structr.org
=== Use Cases ===
*http://www.bigdata-insider.de/neo4j-hilft-bei-aufdeckung-von-finanzskandal-a-528727/
*http://neo4j.com/blog/analyzing-panama-papers-neo4j/
== Orchestrierung und Architekturen ==
*[https://neo4j.com/blog/neo4j-container-orchestration-kubernetes-docker-swarm-mesos/ Neo4j Container Orchestration with Kubernetes, Docker Swarm & Mesos]


[[Kategorie:Datenbanken]]
[[Kategorie:Datenbanken]]

Version vom 22. März 2020, 10:33 Uhr

Auf dieser Seite befasse ich mich mit der Graph-Datenbank Neo4j.

Allgemein

  • Neo4j Homepage
  • High-performance NoSQL graph database
  • Knoten (Nodes) und Kanten (Relationships)
  • Knoten und Kanten werden ergänzt um "Properties" als Schlüssel/Werte-Paare (Key/Value), auch als Array möglich -> Property-Graph-Modell

Grundlagen

Neo4j kennt vier Grundelemente eines Graphen:

  • Nodes
  • Relationships
  • Properties
  • Labels

Artikel

GraphGist

Dokumentation

Interfaces:

Performance Tuning:

Videos:

Entwicklung

Einbettung mittels PHP:

Visualisierung

Installation

User und Rechte

Wrapper-User im System einrichten und in conf/neo4j-wrapper.conf konfigurieren:

wrapper.user=neo4j

Die Verzeichnisse conf und data sollten spezielle Rechte bzw. Eigentümer besitzen:

# ls -la
total 304
drwxr-xr-x  8 root  root    4096 Okt 16 23:20 .
drwxr-xr-x 15 root  root    4096 Nov 18 13:51 ..
drwxr-xr-x  3 root  root    4096 Nov 18 13:51 bin
-rw-r--r--  1 root  root   93430 Okt 16 23:20 CHANGES.txt
drwxr-xr-x  3 neo4j neo4j   4096 Nov 18 13:53 conf
drwxr-xr-x  6 neo4j neo4j   4096 Nov 18 13:53 data
drwxr-xr-x  2 root  root    4096 Nov 18 13:51 lib
-rw-r--r--  1 root  root  125005 Okt 16 23:20 LICENSES.txt
-rw-r--r--  1 root  root   36045 Okt 16 23:20 LICENSE.txt
-rw-r--r--  1 root  root    5959 Okt 16 23:20 NOTICE.txt
drwxr-xr-x  2 root  root    4096 Nov 18 13:51 plugins
-rw-r--r--  1 root  root    1569 Okt 16 23:20 README.txt
drwxr-xr-x  4 root  root    4096 Nov 18 13:51 system
-rw-r--r--  1 root  root    4318 Okt 17 01:21 UPGRADE.txt

Boot Script

Siehe offizielle Anleitung.

Authentifizierung

Standard:

neo4j/neo4j

mit curl:

curl ... -u neo4j:pw ...

Password in

/data/dbms/auth

Authentifizierung ein/ausstellen:

conf/neo4j-server.properties

Tipps und Tricks

Allgemein

curl localhost:7474

Cypher

Create nodes and relations

Mensch ist Label. m1 und m2 sind "Variablen", die später im Cypher-Script genutzt werden können.

Nodes:

create (m1:Mensch {name:'Adam', type:'Mann', location:'Paradies'})
create (m2:Mensch {name:'Eva', type:'Frau', location:'Paradies'})
create (t1:Haustier {name:'Snakie', type:'Schlange', location:'Paradies'})
create (t2:Haustier {name:'Doggie', type:'Hund', location:'Paradies'})

Relations:

create (t1)-[:IS_PET_OF]->(m2)
create (t2)-[:IS_PET_OF]->(m1)
create (m1)-[:IS_PARTNER_OF {type:'married'}]->(m2)

Abfragen

Nodes:

MATCH (n) RETURN n LIMIT 100

Nur die Ids der Nodes:

match (n) return id(n) as ID

Nodes und Relationships:

START n=node(*) MATCH (n)-[r]->(m) RETURN n,r,m;
MATCH (n)-[r]->(m) RETURN n AS FROM , r AS `->`, m AS to;

Mit Index:

start n=node:node_audo_index("term:*") return n;

oder

http://localhost:7474/db/data/index/auto/node/?query=term:*

Siehe Plugins für Abfragen:

http://neo4j.com/docs/stable/server-plugins.html

Delete

Delete a node:

MATCH (n { name: 'Adam' }) DELETE n

Delete a node with relationships

MATCH (n { name: 'Adam' })-[r]-() DELETE n, r

Delete ALL nodes with relationships

MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r

import-cypher

  • Variablen nicht mit '' umschließen (auch nicht bei Strings mit Leerzeichen), weil sonst {Name} als Wert abgespeichert wird.
Falsch
import-cypher -d , -i in.csv -o out.txt create (n:#{Label} {name: '{Name}'}) return *
Richtig
import-cypher -d , -i in.csv -o out.txt create (n:#{Label} {name: {Name}}) return *
  • Datentyp kann im Import-File angegeben werden. Default ist "string". Integer dürfen nicht leer sein - wenn leer sein soll, dann Property weglassen. Es gibt kein NULL.
  • neue Features in 2.2: mehrere Input-Dateien, die man miteinander verbinden kann über Referenzen

Browser

Getting started

:play welcome
:play start
:play sysinfo

Diverses

:history
:style
:config
:schema (prüft u.a. ob Index verfügbar)
:clear
:help keys
:help commands

Query Templates

  • für "create" und "find"

Planner

Query Plan erstellen als Dry-Run für Queries - keine Execution:

explain <query>

Planner:

  • PLANNER RULE
  • PLANNER COST - neu in 2.2 in der Regel schneller

Profile, prüft ob Query Plan verfügbar:

profile <query>

Import und Export von Daten

Kompletter Dump:

neo4j-sh -c dump > export.cypher

Direktes Importieren eines Dumps in eine andere DB:

db1/bin/neo4j-sh -path db1/data/graph.db/ -c dump | db2/bin/neo4j-shell -path db2/data/graph.db/

REST API

curl -v http://localhost:7474/db/data/
curl -v http://localhost:7474/db/data/node/84

Namen

Nicht verifiziert (besonders die Aussagen zu Leerzeichen):

  • Node Labels mit camelCase, dürfen keine Leerzeichen enthalten, erster Buchstabe groß, z.B. "CarOwner".
  • Property Namen mit camelCase (ohne Leerzeichen), erster Buchstabe klein, z.B. "isMale".
  • Property Values mit '' oder "" umschließen, wenn als String.
  • http://google-styleguide.googlecode.com/svn/trunk/jsoncstyleguide.xml
  • Leerzeichen mit `` umschließen.

Datentypen

  • Zahlen werden zu Integers oder Floats, wenn nicht mit '' oder "" umschlossen.

Beispiele

Switches und Ports

Anwendungen

Tools

Use Cases

Orchestrierung und Architekturen