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.

May I create multiple indexes in one statement?

lingvisa
Graph Fellow

3.5.17

create index on:Brand(name)
create index on:Brand(type)

Is there a way to combine these two into one cypher command?

2 REPLIES 2

intouch_vivek
Graph Steward

You can not create multiple index with on Create statement.
However multiple cypher statements can run in one go by Enable multi statement query editor

       with self._driver.session() as session:
                constraint_command = "CREATE CONSTRAINT ON (n:" + label + ") ASSERT n.ID IS UNIQUE"
                index_command_1 = "CREATE index on:" + label + "(type)"
                index_command_2 = "CREATE index on:" + label + "(name)"
                index_command_3 = "CREATE index on:" + label + "(channel)"
                session.write_transaction(
                    lambda tx:
                    tx.run(constraint_command))
                session.write_transaction(
                    lambda tx:
                    tx.run(index_command_1))
                session.write_transaction(
                    lambda tx:
                    tx.run(index_command_2))
                session.write_transaction(
                    lambda tx:
                    tx.run(index_command_3))

Can the 3 tx.run(index_command_x) be merged into one run?

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online