How can i use index in relationship?

relationship
index

(Naval) #1

Neo4j query:

MATCH p=()-[r:HasCustomer]->() where r.numer_of_visits >= 2 and r.numer_of_visits < 4 AND r.merchant_id = 428

RETURN r.customer_id

Started streaming 692246 records after 2 ms and completed after 13800 ms, displaying first 1000 rows.

Mysql Query

SELECT customer_id FROM customers_merchant_map where merchant_id = 428 and numer_of_visits >=2 and numer_of_visits <4

Showing rows 0 - 24 (692402 total, Query took 0.0019 seconds.)

How to optimize this query time ?


(Andrew Bowman) #2

Neo4j's schema index doesn't currently support indexed relationship properties.

While there is a way to leverage the older lucene explicit index to create an index of relationship properties, it's entirely manual, so it's up to you to update the index whenever relationships of the given type are added or removed or the properties changed.

We instead recommend refactoring your model. If you need to perform an index lookup of something, that usually suggests that thing would be better modeled as a node. As a node you are able to create the indexes and constraints you need for quick lookup.

At the very least, merchant_id suggests you should have a :Merchant node in your graph with a unique id.