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.

Create multiple index in one cypher statement?

lingvisa
Graph Fellow

According to this:

Creating multiple indexes in one cypher statement is possible. But I tried, it is still invalid syntax. Is this supported or not?

CREATE INDEX effect_name FOR (n:Effect) on (n._name)
CREATE INDEX beauty_name FOR (n:Beauty) on (n._name)
1 ACCEPTED SOLUTION

Not too much gain, but just save a few lines of code.

View solution in original post

3 REPLIES 3

Hello @lingvisa

This syntax is only working on Neo4j browser if you enable multi-statement query editor as said on the stack overflow post.

If you want to use the BOLT protocol for example, you should be able to cheat (not sure it's working right):

CREATE INDEX effect_name FOR (n:Effect) on (n._name)
UNION
CREATE INDEX beauty_name FOR (n:Beauty) on (n._name)

Regards,
Cobra

but is there anything to be gained by doing such.
Presumably creating an index on a label / property is a rare experience in that I might create said index today on :Person(name) and then the index is there for good such that I never need to recreate etc. I'm not sure I understand see the need/benefit of creating N indexes in one statement/transaction. Also it should be noted that a create index will return immediately for the end user but the index is then populated in the background and this could take N seconds/minutes depending on the volume of data.

Finally, the originally referenced url https://stackoverflow.com/questions/20894532/multiple-create-index-on-in-one-cypher-query was originally authored almost 7 years ago. It may still be valid but generally the date when authored should be considered

Not too much gain, but just save a few lines of code.