0
votes

In Neo4J 2.x I used auto-indexing of relationships, which then allowed me to do search based on relationship properties that were indexed.

In Neo4J 3.x this doesn't work.

In Neo4J 2.x I'd set in neo4j properties:

relationship_auto_indexing=true

and set several properties of relationships to be indexed using

relationship_keys_indexable=user,context,statement,gapscan

Then I would use the old 1.x Cypher query to first identify all the relationships made by the user of the type TO, reading their context property and then matching it to the node that had a specific Context property and then matching the nodes from that context made by that user and retrieving them. The query looked something like

START rel=relationship:relationship_auto_index(user='userid') WHERE TYPE(rel)='TO' WITH DISTINCT rel MATCH (ctx:Context) WHERE rel.context = ctx.uid AND (ctx.name="neo4j3" ) RETURN DISTINCT STARTNODE(rel).uid AS source_id, STARTNODE(rel).name AS source_name, ENDNODE(rel).uid AS target_id, ENDNODE(rel).name AS target_name, rel.uid AS edge_id, ctx.name AS context_name, rel.statement AS statement_id, rel.weight AS weight;

In Neo4J 3.x this query doesn't work and I believe the indexing is done differently.

I have two questions:

1) Do I have to manually index relationship or it is done automatically in 3.x?

2) What query would I use instead of START rel=.... — any alternative to search using relationship properties?

1

1 Answers

1
votes

You can do the same thing in 3.X, but differently.

Yes, you have to index the relationship manually. With APOC you can create a manual index for your relationships.

This is the query to populate your index :

MATCH ()-[r:MY_RELATIONSHIPS]->()
CALL apoc.index.addRelationship(r,['user'])
RETURN count(*)

An then you can retrieve your relationships like than :

CALL apoc.index.relationships('MY_RELATIONSHIPS','userid:userid') YIELD rel, start , end
RETURN rel, start, end

Link to the doc : https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_using_manual_index_on_relationship_properties

Moreover, to automacly populate your manual index, you can also create a trigger with apoc (https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_triggers_examples)