0

I'd like to setup Neo4j APOC trigger that will add all relationship properties to manual index, something like the following:

CALL apoc.trigger.add('HAS_VALUE_ON_INDEX',"UNWIND {createdRelationships} AS r MATCH (Decision)-[r:HAS_VALUE_ON]->(Characteristic) CALL apoc.index.addRelationship(r,['property_1','property_2']) RETURN count(*)", {phase:'after'})

The issue is that I don't know the exact set of HAS_VALUE_ON relationship properties because I use the dynamic properties approach with Spring Data Neo4 5.

Is it possible to change this trigger declaration to be able to add all of the HAS_VALUE_ON relationship properties(existing and ones that will be created in future) to the manual index instead of the preconfigured ones( like ['property_1','property_2'] in the mentioned example) ?

alexanoid
  • 24,051
  • 54
  • 210
  • 410

1 Answers1

2

If you do not know the set of properties in advance, then you can use the keys function to add all properties of the created relationships to the index:

CALL apoc.trigger.add(
  'HAS_VALUE_ON_INDEX',
  'UNWIND {createdRelationships} AS r MATCH (Decision)-[r:HAS_VALUE_ON]->(Characteristic) 
   CALL apoc.index.addRelationship(r, keys(r)) RETURN count(*)',
   {phase:'after'}
)
stdob--
  • 28,222
  • 5
  • 58
  • 73