0
votes

I have a question about how to efficiently filtering search results based on a property of a relationship.


I have a graph like this:

(:PERSON)-[:WORKED_WITH {weight:30}]->(:PERSON)

with over 300.000 nodes labeled PERSON and over 15.000.000 edges labeled :WORKED_WITH (each has an integer weight).


Now for example I want to have the 10 node combinations with the highest weight between them. So my query looks like this:

MATCH (n:PERSON)-[r:WORKED_WITH]->(m:PERSON)
RETURN n.name, m.name, r.weight
ORDER BY r.weight DESC
LIMIT 10;

As I recently read it is not possible to create an index on a property of a relationship. I read you could create nodes for partitions like <50, 50-100, >100 as an example, but that does not feel like best practise... Is there a possibility to use something that behaves like an (inequality) index? Or what would you suppose to solve this kind of problems efficient?

Regards Wolfgang

1

1 Answers

0
votes

Stefan Armbruster explains the point (and your options) well in How to create an index on a property of a relation.

If the relationship is the sole entrypoint into your graph (read: if there is no other way to reduce the initial search) ... then you may want to remodel it (as a node). That may indeed not "feel" correct, but it is best practice.

Hope this helps, Tom