Introduction to graph database Neo4j

Once there, the in 2005, I got sick of the idea of creating a knowledge base that does not have a clear table structure and would work on the principle of named nodes and links between them. The idea was such that the node itself is not carrying any information and all information would set its surroundings and relationships. I then wrote a little code repository of nodes and links, as well as simple operations on them, but do not store information in the nodes was too hard and I’m tied to each node one text property (in Neo4j in a knot, you can burn a lot of properties of different types and then refer to them by name).

This engine was originally written in C #, then rewritten several times, but gradually interest in him I lost. He remembered that his development as recently stumbled upon Neo4j, and learn some more detailed ideas wanted to see it.

Neo4j I installed on Dev, it turned out that the built front-end has a web interface and is available at http://localhost:7474

After the transition to the address I was asked to enter a user name and password, while also giving a hint that there is a credit default username “node4j” and the password is the same. Then I waited for the welcome page, which had three main buttons – Start Learning, Write Code and Monitor :

The first thing I went to the page and monitoring unit immediately above the buttons added another unit in which I saw the statistics database (on the screenshot I’ve managed to add one node):

It turned out that the new information is added to the screen such blocks that can be removed to fix, flipping, and the oldest of them fail down.

At the top was the command line to execute the local query language similar to SQL only now it’s called “Cypher Query Language”. I immediately wanted anything else to add to the database, but not as hard as it was proposed in the built-example “play movie graph” – there was a whole page of commands, which apparently created a whole heap of entities with properties and relationships between them. Instead, I went to the link to the description of the CREATE command and example as CREATE (n), by creating a simple single node.

Then I finally decided to find where the prescribed ports on which the server is waiting for the connection to connect to virtualke from your browser instead of the local browser virtualke. It was found necessary to uncomment the line

#org.neo4j.server.webserver.address=0.0.0.0

in the file conf/neo4j-server.properties

Then I tried to create multiple nodes:

CREATE (a:Country {name:'Украина'}),(b:Country {name:'Россия'}),(c:Country {name:'Беларусь'}),(d:Country {name:'Казахстан'})

I got:

Added 3 labels, created 4 nodes, set 4 properties, statement executed in 664 ms.

When I wanted to link the country’s ratio of ‘Border’, that is, specify which border with what turned out that Neo4j attitude can only be one-way, but from the database can be done while ignoring the direction of the sample. I had to put up with it, and to establish links casual direction:

MATCH (a:Country {name:'Украина'}),(b:Country {name:'Россия'}),(c:Country {name:'Казахстан'}),(d:Country {name:'Беларусь'}) CREATE (a)-[r:Border]->(b),(a)-[t:Border]->(d),(b)-[y:Border]->(c),(d)-[u:Border]->(b)

Here, first in the variables a, b, c, d to select all the desired country and then set connection between them labeled (Label) “Border”. Admire on to get a picture, you can select all the links “Border”

MATCH ()-[r:Border]-() RETURN r

Or all counties:

MATCH (a:Country) RETURN a

After practicing, I added a few more countries and the links between them, it was possible to obtain such a picture:

It is said that on the graph due although attract related nodes, but still often housed not the most optimal way, and if they move the hand, you can get a good placement than previously.

It seemed to me that the built-in renderer should not be the only one, and a little searching, I found a few examples of visualizations:

http://neo4j.com/developer/guide-data-visualization/#_presentation_svg_based_graph_interaction

Interestingly, the connection can also have properties as a node, but it seemed to me not very clear limit on the number of types of links (one source 32768 and 65536 on the other). In my database types of bonds were set by the nodes, allowing if necessary to build a hierarchy of types of relationships and have more varieties.

The shell of my database looks like this:

There was a common tree essences, as well as separate forms for use with certain types of entities, such as personnel (in fact the telephone directory), the catalog of CDs. Anything you can view a list or a tree. It was assumed that I develop as a result of some convenient form of storage of knowledge that can be easily intertwined with each other and do not have a clear uniform structure. Now of course I do not think that necessarily had to develop a database from scratch, and it was quite possible for a basis, Firebird, MySQL and implement a mechanism for storing / sample nodes and links between them in the form of tables. Now one of his experiments, and I actually do.

Leave a Comment

Your email address will not be published.