APOC 4.2.0.4 and manual indexes

I'm trying to migrate to APOC 4.2.0.4 and right now don't know how to rewrite the following constructions:

session.query("CALL apoc.index.list() YIELD name CALL apoc.index.remove(name) YIELD name AS removedIndexName RETURN removedIndexName", new HashMap<>());

and the same for the following:

if (!triggerExists("HAS_VALUE_ON_CREATED_RELATIONSHIPS_TRIGGER")) {
			session.query(
					"CALL apoc.trigger.add('HAS_VALUE_ON_CREATED_RELATIONSHIPS_TRIGGER', \"UNWIND $createdRelationships AS r WITH r WHERE type(r) = 'HAS_VALUE_ON' CALL apoc.index.addRelationship(r, keys(r)) RETURN true\", {phase:'before'})",
					new HashMap<>());
		}

		if (!triggerExists("HAS_VALUE_ON_ASSIGNED_RELATIONSHIP_PROPERTIES_TRIGGER")) {
			session.query(
					"CALL apoc.trigger.add('HAS_VALUE_ON_ASSIGNED_RELATIONSHIP_PROPERTIES_TRIGGER', \"UNWIND keys({assignedRelationshipProperties}) AS key UNWIND {assignedRelationshipProperties}[key] AS map WITH map WHERE type(map.relationship) = 'HAS_VALUE_ON' CALL apoc.index.addRelationship(map.relationship, keys(map.relationship)) RETURN true\", {phase:'before'})",
					new HashMap<>());
		}

		if (!triggerExists("HAS_VALUE_ON_DELETED_RELATIONSHIPS_TRIGGER")) {
			session.query(
					"CALL apoc.trigger.add('HAS_VALUE_ON_DELETED_RELATIONSHIPS_TRIGGER', \"UNWIND {deletedRelationships} AS r WITH r WHERE type(r) = 'HAS_VALUE_ON' CALL apoc.index.removeRelationshipByName('HAS_VALUE_ON', r) RETURN true\", {phase:'before'})",
					new HashMap<>());
		}

		if (!triggerExists("HAS_VALUE_ON_REMOVED_RELATIONSHIP_PROPERTIES_TRIGGER")) {
			session.query(
					"CALL apoc.trigger.add('HAS_VALUE_ON_REMOVED_RELATIONSHIP_PROPERTIES_TRIGGER', \"UNWIND keys({removedRelationshipProperties}) AS key UNWIND {removedRelationshipProperties}[key] AS map WITH map WHERE type(map.relationship) = 'HAS_VALUE_ON' CALL apoc.index.addRelationship(map.relationship, keys(map.relationship))  RETURN true\", {phase:'before'})",
					new HashMap<>());
		}

looks like apoc.index.list() was removed from the library. What should I use instead of this right now?

Hello @myshareit :slight_smile:

You should have a look here:

  • to drop an index: DROP INDEX missing_index_name IF EXISTS
  • to list all indexes: SHOW INDEXES

Your triggers should still work.

Regards,
Cobra

Hello @Cobra and thanks for your answer!

In trigger looks like the following part doesn't work:

CALL apoc.index.addRelationship(map.relationship, keys(map.relationship))

How to refactor it ?

It's not possible to add indexes on relationships but it will be possible in the future in Cypher.

What is the latest Neo4j and APOC version where we have such feature ? Probably I'll upgrade my application only to this version for now. Is it a good idea?

For the moment, it is not possible to add indexes on the relations but it will be possible in the future. I advise you to use the latest version of Neo4j. You can always develop a workaround to check if the index exists before adding it until Neo4j adds the ability to create indexes on relationships.

Unfortunately my existing logic extensively uses such functionality.. so refactoring will be huge. Right now I'm on Neo4j 3.4.7 and would like to upgrade to some newer version.
Also, I failed to switch to SDN6 and right now trying SDN5..

I don't think you can upgrade without refactoring or you will have to wait Neo4j develop this functionality but they didn't give any date right now.

Thanks, I'll try. Btw, do you know is it a good idea to upgrade to SDN5 and not SDN6? How long SDN5 will be supported from now?

I'm sorry, I don't know :confused: