2

I'm working on a Neo4j plugin and need to retrieve a relationship by property value.

I have access to Neo4j GraphDatabaseService which has a very convenient method GraphDatabaseService.findNode(Label label, String property , String value).

I am looking for the relationship-counterpart of this method, something like GraphDatabaseService.findRelationship(RelationshipType type, String property , String value).

Does this exist? Is it on the roadmap? Is there another way?

david_p
  • 5,722
  • 1
  • 32
  • 26
  • 2
    This doesnt exist and is not on the roadmap, the only way is to use Lucene indices to index the property values. You can have a look at graphaware-uuid to see how we do it for relationship uuids. – Christophe Willemsen Jun 21 '16 at 19:54
  • Right now only nodes are supported with schema indexes, what would be your use-cases for finding relationships by value without the context of the nodes around them? – Michael Hunger Jun 21 '16 at 21:04
  • You can access manual indexes for relationship via the Java API, it's pretty nice, because you can both find rels just via property but also in the context of either of their end-nodes. – Michael Hunger Jun 21 '16 at 21:05

2 Answers2

1

Right now only nodes are supported with schema indexes.

What would be your use-cases for finding relationships by value without the context of the nodes around them?

You can access manual indexes for relationship via the Java API, it's pretty nice, because you can both find relationships just via property but also in the context of either of their end-nodes. If you create one index-per rel-type it's also really good for nodes with many relationships to filter a few out by also passing in the start or end-node. That's what I added support for in the APOC procedure library.

But you will have to add relationships to that index manually.

Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • Thank you Michael! My use-case is the neo4j-to-elasticsearch plugin. I'm adding support for relationships indexing and would like to retrieve relationships by UUID (when a relationships has matched a search query in ES). From Christophe's answer, I guess I just have to access the UUID plugin from the ElasticSearch plugin and I will be good :) – david_p Jun 22 '16 at 08:07
0

Summing up from Michael and Christophe's answers:

  • finding a Relationship by property value with a schema index is not implemented
  • finding relationships by property is possible using manual indexes
  • GraphAware's UUID Neo4j plugin does just that (uses manual indexes) for UUIDs

To get a relationship by UUID, here is the code:

public Relationship getRelByUuid(GraphDatabaseService database, String uuid) {
    UuidReader reader = new DefaultUuidReader(
        getStartedRuntime(database).getModule(UuidModule.class).getConfiguration(),
        database
    );
    return database.getRelationshipById(uuidReader.getRelationshipIdByUuid(uuid));
}
david_p
  • 5,722
  • 1
  • 32
  • 26