Neo4j Relationship Schema Indexes

Using Neo4j 2.1.4 and SDN 3.2.0.RELEASE

I have a graph that connects nodes with relationships that have a UUID associated with them. External systems use UUIDs as a means to identify the source and target of a relationship. In Spring Data Neo4j (SDN) we have a class @RelationshipEntity(type="LINKED_TO")

with a field @StartNode

, @EndNode

and a String uuid

. The field uuid

is equal @Indexed

and the resulting schema definition in Neo4j appears as

neo4j-sh (?)$ SCHEMA
==> Indexes
...
==>   ON :Link(uuid) ONLINE
...

      

However, a cypher query is made to the data, like

MATCH ()-[r:LINKED_TO]->() WHERE uuid=’XXXXXX’ RETURN r;

      

performs a full database scan and takes a long time

If I try to use the index by running

MATCH ()-[r:LINKED_TO]->() USING INDEX r:Link(uuid) WHERE uuid=’XXXXXX’ RETURN r;

      

I get

SyntaxException: Type mismatch: expected Node but was Relationship.

      

As I understand it, the relationship should be first class citizens in Neo4j, but I can't figure out how to use the index on the relationship to prevent the graph equivalent of a table scan in the database to find the relationship.

I know there are posts such as How to use relationship index in Cypher that asks similar things, but this linkconnected between two knots. If I were to convert the link to Node, we would create a Node to represent the relationship, which seems to be wrong when we are working in the graph database - I would end up with ()-[:xxx]->(:Link)-[:xxx]->()

to represent a single relationship. This would make the model dirty purely because the reference cannot be represented as a relation.

Link

has a unique, shared key attached to it that I want to use. The schema output shows that an index exists for this field - I just can't use it.

Does anyone have any suggestions?

Many thanks,

Dave

+3


source to share


1 answer


Schema indexes are only available for nodes. The only way to index relationships is to use legacy indexes or autoindexes. Deprecated indexes should be used explicitly in the sentence START

:

START r=relationship:my_index_name(uuid=<myuuid>)
RETURN r

      



I'm not sure how this can be used in conjunction with SDN.

Note: The required ratio index is almost always a sign that you are doing something wrong in your graph data model. Anything that is thing

or has an identity in your domain must be node. So if a uuid is required for a relation, it is possible that the relation refers to the substance and therefore needs to be converted to a node having an inbound relation to a previous start node and an outbound relation to a previous end of a node.

+1


source







All Articles