Neo4j: Unterschied zwischen den Versionen

aus www.kruedewagen.de, Homepage von Ralf und Judith Krüdewagen (Kruedewagen)
Zur Navigation springen Zur Suche springen
 
(32 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
*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]
*Praxis am Beispiel "Beziehungen unter Amazon Reviewern zur Erkennung von Fake-Bewertungen": siehe LM 07/20 S.30
**yaml-Datei einlesen mit Go-Script, Nutzung vom Similarity-Algorithmus, Docker-Installation (Dockerfile), Plugins nutzen (Algorithmen)
**https://www.linux-magazin.de/links/?id=44519 , https://www.linux-magazin.de/magazine/listings/#2020-07&030-ti-graphdb-neo4j
**[https://www.linux-magazin.de/videos/snapshot-07-2020-graph-datenbank-neo4j-enttarnt-gefaelschte-bewertungen/ Video - Snapshot 07/2020: Graph-Datenbank Neo4j enttarnt gefälschte Bewertungen
*[https://neo4j.com/blog/fraud-detection-with-graph-data-science-infographic/ Find More Fraud with Graph Data Science] (Infographic)
*[https://neo4j.com/blog/build-knowledge-graph-from-scratch-even-if-youre-not-full-blown-developer/ How to Build a Knowledge Graph from Scratch Even If You’re Not a Full-Blown Developer]
=== 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 37: Zeile 57:
*[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]
*[https://neo4j.com/blog/secret-sauce-neo4j-modeling-graphconnect/ The Secret Sauce of Neo4j: Modeling and Querying Graphs]
*[https://neo4j.com/blog/graphcast-what-is-graph-database-in-10-minutes/ What Is a Graph Database in 10 Minutes], https://www.youtube.com/watch?v=REVkXVxvMQE
*[https://neo4j.com/blog/graphcast-an-introduction-to-neo4j/ #GraphCast: An Introduction to Neo4j]
Literatur
*[https://neo4j.com/blog/introducing-graph-databases-for-dummies/ Introducing Graph Databases For Dummies]


== Entwicklung ==
== Entwicklung ==
Zeile 45: Zeile 72:
*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 53: Zeile 80:
**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://neo4j.com/developer/r/ Neo4j for R Developers and Data Scientists]
*[http://linkurio.us Linkurious]
*[https://neo4j.com/bloom/ Neo4j Bloom]
**https://neo4j.com/docs/#bloom
**https://neo4j.com/developer/neo4j-bloom/
**[https://neo4j.com/blog/graph-visualization-just-got-easier-introducing-neo4j-bloom-1-4/ Graph Visualization Just Got Easier: Introducing Neo4j Bloom 1.4]
**https://medium.com/neo4j/bloom-ing-marvellous-a2be0c3702bb
**https://www.youtube.com/watch?v=Zz-96Q8Ru5U
**Desktop-Version: kostenlos; Server: lizenzpflichtig
=== Prototyping / Design ===
*[https://www.figma.com/ Figma] mit GitLab Plugin: https://about.gitlab.com/blog/2020/10/02/product-development-management/ , https://www.figma.com/community/plugin/860845891704482356/GitLab


== Installation ==
== Installation ==
=== Rechte ===
=== 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:
Die Verzeichnisse '''conf''' und '''data''' sollten spezielle Rechte bzw. Eigentümer besitzen:
<pre>
<pre>
Zeile 93: Zeile 134:


== 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 151: Zeile 196:
==== Getting started ====
==== Getting started ====
  :play welcome
  :play welcome
:play start
:play sysinfo


==== Diverses ====
==== Diverses ====
Zeile 210: Zeile 257:


== 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]]

Aktuelle Version vom 10. Juli 2021, 11:38 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:

Literatur

Entwicklung

Einbettung mittels PHP:

Visualisierung

Prototyping / Design

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