Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relationship Labels and Index in Neo4J

Tags:

indexing

neo4j

It's possible to label the nodes in the new Neo4J 2.0.1, but does that same labelling work on relationships? If I have a relationship of the type :TO, can I create an index on its "statement" property like that?

 CREATE INDEX ON :TO(statement)

Thank you!

like image 299
Aerodynamika Avatar asked Mar 16 '14 12:03

Aerodynamika


People also ask

What are labels in Neo4j?

Neo4j recently introduced the concept of labels and their sidekick, schema indexes. Labels are a way of attaching one or more simple types to nodes (and relationships), while schema indexes allow to automatically index labelled nodes by one or more of their properties.

What is index in Neo4j?

In Neo4j, index is a data structure which is used to improve the speed of data retrieval operations in a database. An index can be created over a property on any node that has been given a label. Once an index is created, Neo4j will manage it and keep it up to date whenever the database is changed.

What are relationships in Neo4j?

Relationships describes a connection between a source node and a target node. Relationships always has a direction (one direction). Relationships must have a type (one type) to define (classify) what type of relationship they are.

Why are labels used in Neo4j database?

Labels are used when defining constraints and adding indexes for properties (see Schema). An example would be a label named User that you label all your nodes representing users with. With that in place, you can ask Neo4j to perform operations only on your user nodes, such as finding all users with a given name.


1 Answers

a) you cannot have labels on relationships. A relationship has one type (which can be thought of kind of label). If you need multiple labels, you just create multiple relationships with different types

b) schema indexes on relationships are not possible. A graph query typically starts at nodes and not at relationships since nodes are the "things" in your domain. Starting at a relationship is IMHO often a indication to rethink your graph model. If you're still convinced you need relationship indexing, you can go with legacy indexing.

like image 119
Stefan Armbruster Avatar answered Sep 16 '22 14:09

Stefan Armbruster