Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-06-2022 08:33 AM
Server community edition 4.4.7
Is there a way to create indexes for all the nodes who have a property with a given name?
Solved! Go to Solution.
06-07-2022 08:08 AM
This is the solution if someone is interested:
// Create an index on all
CALL db.labels() YIELD label
UNWIND label as lab
WITH
"CREATE INDEX index_created_at_" + lab + " IF NOT EXISTS FOR (n:" + lab + ") ON (n.CREATED_AT)" as v1,
"CREATE INDEX index_updated_at_" + lab + " IF NOT EXISTS FOR (n:" + lab + ") ON (n.UPDATED_AT)" as v2,
"CREATE INDEX index_deleted_at_" + lab + " IF NOT EXISTS FOR (n:" + lab + ") ON (n.DELETED_AT)" as v3
call apoc.cypher.runSchema(v1,{}) YIELD value as v11
call apoc.cypher.runSchema(v2,{}) YIELD value as v12
call apoc.cypher.runSchema(v3,{}) YIELD value as v13
return v11, v12, v13
06-06-2022 09:14 AM
I tried with:
CALL db.labels() YIELD label
UNWIND label as lab
call apoc.cypher.run("CREATE INDEX index_created_at_" + lab + " IF NOT EXISTS FOR (n:" + lab + ") on (n.'CREATED_AT')",{lab: lab}) YIELD value as v1
but it returns an error:
Neo.ClientError.Procedure.ProcedureCallFailed
Failed to invoke procedure `apoc.cypher.run`: Caused by: org.neo4j.exceptions.SyntaxException: Invalid input 'INDEX': expected "(", "allShortestPaths" or "shortestPath" (line 1, column 31 (offset: 30))
" WITH $`lab` as `lab` CREATE INDEX index_created_at_ErrorArea IF NOT EXISTS FOR (n:ErrorArea) on (n.'CREATED_AT')"
^
where ErrorArea is the first returned label.
Any suggestion?
06-07-2022 08:08 AM
This is the solution if someone is interested:
// Create an index on all
CALL db.labels() YIELD label
UNWIND label as lab
WITH
"CREATE INDEX index_created_at_" + lab + " IF NOT EXISTS FOR (n:" + lab + ") ON (n.CREATED_AT)" as v1,
"CREATE INDEX index_updated_at_" + lab + " IF NOT EXISTS FOR (n:" + lab + ") ON (n.UPDATED_AT)" as v2,
"CREATE INDEX index_deleted_at_" + lab + " IF NOT EXISTS FOR (n:" + lab + ") ON (n.DELETED_AT)" as v3
call apoc.cypher.runSchema(v1,{}) YIELD value as v11
call apoc.cypher.runSchema(v2,{}) YIELD value as v12
call apoc.cypher.runSchema(v3,{}) YIELD value as v13
return v11, v12, v13
All the sessions of the conference are now available online