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.

Using Cypher to generate Cypher statements to recreate indexes and constraints

The following can be used to extract index defintions and constraint defintions from an existing database and the resultant
output can be played back on another Neo4j database.

To extract Cypher CREATE INDEX statements run:

CALL db.indexes() YIELD description
RETURN 'CREATE ' + description

To extract Cypher CREATE CONSTRAINT statements run:

CALL db.constraints() YIELD description
RETURN 'CREATE ' + description
2 REPLIES 2

darryn
Node Clone

Is there a way to also get the full text indexes that were created?

ie if i had run

CALL db.index.fulltext.createNodeIndex("titlesAndDescriptions",["Movie", "Book"],["title", "description", "review"])

the above queries seem to miss these full text indexes

in 4.0.x forward there is now call db.schemaStatements(); which will will produce a createStatement and dropStatement for all indexes and include the index provider. For example and when using bin/cypher-shell and with 4.0.3

@neo4j> create index movieTitles for (n:Movies) on (n.title);
0 rows available after 111 ms, consumed after another 0 ms
Added 1 indexes

and then

@neo4j> call db.schemaStatements() yield dropStatement;
+----------------------------+
| dropStatement              |
+----------------------------+
| "DROP INDEX `movieTitles`" |
+----------------------------+

and

@neo4j> call db.schemaStatements() yield createStatement;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| createStatement                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "CALL db.createIndex('movieTitles', ['Movies'], ['title'], 'native-btree-1.0', {`spatial.cartesian-3d.min`: [-1000000.0, -1000000.0, -1000000.0],`spatial.cartesian.min`: [-1000000.0, -1000000.0],`spatial.wgs-84.min`: [-180.0, -90.0],`spatial.cartesian-3d.max`: [1000000.0, 1000000.0, 1000000.0],`spatial.cartesian.max`: [1000000.0, 1000000.0],`spatial.wgs-84-3d.min`: [-180.0, -90.0, -1000000.0],`spatial.wgs-84-3d.max`: [180.0, 90.0, 1000000.0],`spatial.wgs-84.max`: [180.0, 90.0]})" |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row available after 2 ms, consumed after another 2 ms

and so one could use the dropStatement and createStatements so as to replay to rebuild said indexes/constraints;