7

I want to delete all indexes that exist using cypher in a bulk can it be done? I am using neo4j 3.4.7.

DROP INDEX  ON :Label(attributename)

Does it replace existing indexes if I create the same index in a later stage?

Abdullah Al Noman
  • 2,817
  • 4
  • 20
  • 35
  • The solutions at [StackOverflow: Neo4j how to drop all constraints](https://stackoverflow.com/questions/22357379/neo4j-how-to-drop-all-constraints) and the last solution [StackOverflow: delete multiple indexes via java](https://stackoverflow.com/questions/17516809/what-are-the-cypher-commands-to-delete-index-and-index-entry) may help you. – ThirstForKnowledge Oct 01 '18 at 16:22
  • If you (re) create an identical index, you get no error and the existing one will not be touched. See [StackOverflow: create index on when the index already exists in Neo4j](https://stackoverflow.com/questions/46408327/launching-a-create-index-on-when-the-index-already-exists-in-neo4j). – ThirstForKnowledge Oct 01 '18 at 16:34

2 Answers2

13

A quick way to drop all indexes and constraints is to use the APOC procedure apoc.schema.assert, as follows:

CALL apoc.schema.assert({},{},true) YIELD label, key
RETURN *

The procedure is mainly for ensuring that the DB has the indexes and constraints passed in the first 2 maps, but the third parameter determines whether any other indexes and constraints are dropped. In the above query, the first 2 maps are empty, so the end result is that all indexes and constraints are dropped.

cybersam
  • 63,203
  • 6
  • 53
  • 76
  • 2
    Note that this doesn't apply to compound indexes or node key constraints, and I don't believe it applies to property existence constraints either. – InverseFalcon Oct 01 '18 at 18:42
  • Can I check if an index exists in cypher ? @cybersam – Abdullah Al Noman Oct 02 '18 at 11:59
  • The Cypher language itself has no way to check for index existence. But the APOC plugin has several [procedures for getting index/constraint info](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_schema_information). In particular, `apoc.schema.node.indexExists()` will tell you if a specific index exists. – cybersam Oct 02 '18 at 17:49
  • The existence of an index can be checked with this: one row is returned if a property index exists else zero rows are returned. ` CALL db.indexes() YIELD description WHERE description = "INDEX ON :Publication(source_id)" RETURN *; ` – Dima Korobskiy Oct 25 '19 at 21:06
  • Cypher has had [SHOW INDEXES](https://neo4j.com/docs/cypher-manual/current/indexes-for-search-performance/#indexes-list-indexes) for awhile now. – cybersam Aug 18 '23 at 16:12
5

For release 3.x your can to use built-in procedures Neo4j to delate what index your want. From web browser your can send Cipher query:

CALL db.indexes() - List all indexes in the database.

CALL db.index.fulltext.drop() -Drop the specified index.

or CALL db.index.explicit.drop() - Remove an explicit index - YIELD type,name,config

All possible built-in procedures and parameter for last version here User management for Neo4j

old style do it with CIPHER :

DROP INDEX ON :labelOfNode(propertyOfNode)

CREATE INDEX ON :labelOfNode(propertyOfNode)

abmerday
  • 71
  • 1
  • 6