简体   繁体   中英

Neo4j: Speed up Relationship matching by property inequality

I'm using Neo4j 3.0.5.

My query looks as follows:

MATCH (cd:ConnectionDay)-[c:Connection]->()
WHERE id(cd)= { id } AND c.departure <= { departure }
RETURN c

In my graph, the number of Connection relations is very high and I'm looking for a way to speed up the retrieval. Is there a way to create an index for the departure property?

I'm using the Embedded Java API anyway, so solutions that aren't using Cypher are ok, too.

Aside: It is not recommended that you use native neo4j IDs to find nodes, as after a node is deleted its native ID can be reused. It is safer to add your own property to store an ID that you know is permanently unique.

Neo4j does not currently support indexing for relationship properties. If you want to use indexing, you can alter you data model to "reify" your Connection relationships as nodes. For example, your new data model would look something like this:

(cd:ConnectionDay)-[:CONNECTS_TO]->(c:Connection {departure: 123})-[]->()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM