How do you quickly get the maximum (or minimum) value for a property of all instances of a relationship? You can assume the machine I'm running this on is well within the recommended spec's for the cpu and memory size of graph and the heap size is set accordingly.
Facts:
- Using Neo4j v2.2.3
- Only have access to modify graph via Cypher query language which I'm hitting via PHP or in the web interfacxe--would love to avoid any solution that requires java coding.
- I've got a relationship, call it
likes
that has a single propertyid
that is an integer. - There's about 100 million of these relationships and growing
- Every day I grab new
likes
from a MySQL table to add to the graph within in Neo4j - The relationship property
id
is actually the primary key (auto incrementing integer) from the raw MySQL table. - I only want to add new
likes
so before querying MySQL for the new entries I want to get the maxid
from thelikes
, so I can use it in my SQL query asSELECT * FROM likes_table WHERE id > max_neo4j_like_property_id
How can I accomplish getting the max id
property from neo4j in a optimal way? Please indicate the create statement needed for any index as well as the query you'd used to get the final result.
I've tried creating an index as follows:
CREATE INDEX ON :likes(id);
After the index is online I've tried:
MATCH ()-[r:likes]-() RETURN r.i ORDER BY r.id DESC LIMIT 1
as well as:
MATCH ()-[r:likes]->() RETURN MAX(r.id)
They work but take freaking forever as the explain plan for both indicate no indexes being used.
UPDATE: Holy $?@#$?!!!! It looks like the new schema indexes aren't functional for relationships even though you can create them and show them with :schema
. It also looks as if there's no way with cypher directly to create Legacy Indexes which look like they might solve this issue.
:likes
– Michael Hunger(n:person {id: 'bob'} )-->(:likes {id: 3})-->(:person {id: 'jim'} )
– Ray