cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to query for and then drop index of a given type?

tms
Graph Buddy

I want write a cypher query that shows the index names of a certain type so that I can drop them. I'm using Neo4J-Enterprise v4.4.6 on an AWS EC2 instance running the most recent version of Rocky Linux (CentOS 8).

The documentation asserts that this can be done:

One of the output columns from SHOW INDEXES is the name of the index. This can be used to drop the index with the DROP INDEX command.

I can't find a cypher incantation that puts the name in scope so that I can then drop it.

For example, I can get the name (and type) like this:

SHOW INDEXES YIELD name, type WHERE type='LOOKUP'

This displays the name in Neo4J browser ("index_343aff4e", "index_f7700477" in my case).

How do I then pass the name to `DROP INDEX ..."?

I've tried various permutations of "WITH" and even tried a subquery with no joy.

For example, I tried the following:

CALL {
    SHOW INDEXES YIELD name, type WHERE type='LOOKUP'
}
RETURN name, type

Cypher complains that "SHOW" doesn't work inside the sub-query.

I don't see anything in the docs or on stackoverflow that clarifies this.

2 REPLIES 2

@tms

show indexes yield *

will report many more columns then the default show indexes.
this does include a column named createStatement

To get a Drop statement one can run

show indexes yield name return 'DROP INDEX ' + name + ';' ;

will create the DROP statements

I appreciate your response.

When I get neo4j back on its feet again, I'll try it.