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!
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With