I am trying to insert a number of rows (more than 1 mil) from a CSV file into the graph database, the treasure table needs a relationship to a city, as in a treasure is found in ever city. I have created an index yet neo4j doesn’t seem to be using it:
// Create index to speed up insertion
CREATE INDEX IF NOT EXISTS FOR (ci:City) ON (ci.id);
// Load treasures and link to cities
:auto LOAD CSV FROM 'file:///treasure.csv' AS row_treasure
CALL {
WITH row_treasure
CREATE (t:Treasure {id: row_treasure[0], difficulty: toInteger(row_treasure[1]), terrain: toInteger(row_treasure[2]), city_id: row_treasure[3]})
WITH t, row_treasure
MATCH (ci:City {id: row_treasure[3]})
CREATE (t)-[:HIDDEN_IN]->(ci)
} IN TRANSACTIONS OF 500 ROWS;
This index not being used leads to greater than 10 minute wait time for 500 entries to be inserted. Elsewhere in the same execution I am also using an index yet this one is used correctly:
// Create index to speed up insertion
CREATE INDEX IF NOT EXISTS FOR (co:Country) ON (co.code);
// Load cities and link to countries
:auto LOAD CSV FROM 'file:///city.csv' AS row_city
CALL {
WITH row_city
CREATE (ci:City {id: row_city[0], city_name: row_city[1], latitude: row_city[2], longitude: row_city[3], postal_code: row_city[4], country_code: row_city[5]})
WITH ci, row_city
MATCH (co:Country {code: row_city[5]})
CREATE (ci)-[:LOCATED_IN]->(co)
} IN TRANSACTIONS OF 500 ROWS;
I have tried looking up different types of indexes and how to use them but I have generally been unable to find a solution that does work and uses the indexes.