5

I want to index the existing relationship properties in Neo4J (2.0.1) and also to set up automatic indexing for the ones that will appear in the future.

I found out that it's possible to do that in Neo4J documentation through the legacy auto-indexing as well as the examples of some Java code.

However, as I'm neither an expert in Java, nor want to use "legacy" functionality, I wanted to ask you if there is an easy way to index relationships on a specific property using Cypher command or any other way (rest API?) that wouldn't involve me having to write some Java program and run it (I don't know how to do that).

Thank you for your help!

Community
  • 1
  • 1
Aerodynamika
  • 7,883
  • 16
  • 78
  • 137

3 Answers3

4

My original answer was wrong. Editing so that it doesn't generate confusion to others looking for a solution.

Please refer to Relationship Labels and Index in Neo4J a for correct answer, as @deemeetree pointed out in the comments.

Community
  • 1
  • 1
albertoperdomo
  • 1,941
  • 12
  • 14
  • 2
    Does that actually work? My understanding is that this syntax only works for nodes not for relationships. I just tried something similar and it says it created the index but it isn't actually using it in queries. I think in your example you've actually created an index on nodes labelled WATCHED. – Damon Horrell Mar 17 '14 at 01:37
  • Exactly. This is a wrong answer. Check this out: http://stackoverflow.com/questions/22437106/relationship-labels-and-index-in-neo4j/22444108 – Aerodynamika Mar 17 '14 at 02:06
  • Yes, I was wrong, @deemeetree. I'm editing the answer to reflect that it's wrong. If you think I should remove it just tell me. – albertoperdomo Mar 17 '14 at 15:34
3

Since Neo4j 4.3 (released June 17, 2021), creating relationship property indexes can be done directly with Cypher, as discussed on the Neo4j blog and the 4.3 release notes.

Example from the blog:

CREATE INDEX officerRelationshipProperty
FOR ()-[r:OFFICER_OF]-()
ON (r.role);
bitoffdev
  • 3,134
  • 1
  • 13
  • 16
-3

You can't do indexing on relationship. Indexing is done only on nodes.