2
votes

I've got a neo4j graph with the following structure.

(Account) ---[Transaction]--- (Account)

Transaction is a neo4j relationship and Account is a node.

There are set various properties on each transaction, such as the transaction ID, amount, date, and various other banking information.

I can run a search by Account id, and it returns fine. However when I search by transaction ID, neo4J searches the entire graph instead of using index, and the search fails.

I created indexes using org.neo4j.unsafe.batchinsert.BatchInserterImpl.createDeferredSchemaIndex() for both Account.number and Transaction.txid. The index seems to function for Account (node) searches but not for Transaction (relationship) searches. (I have also enabled auto index for node and relationship, but it doesnt change things)

I'm thinking that indexing on relationship properties is not supported, so considering making intermediate nodes to hold property information. However, I'd prefer to stick to my original design if possible.

Any idea how to proceed?

1

1 Answers

4
votes

You can use legacy indexes or auto indexes to index relationships. Schema indexes do not support indexing relationships.

The reason for that: Typically you use use nodes to model the #things# or #entities# in your domain. Relationship wire up your world and put the nodes into a semantic context. When following that model you typically don't have to index relationships since your queries always start at a #thing# which is always a node.

In your model, you should rethink modelling, I guess it could make sense to have

 (account)-[:send]->(transaction)-[:to]->(account).

So transactions are a thing on its own and therefore become nodes.