Question

I have an existing graph database hosted with neo4j 2.1.0-M02. The data was created by using a BatchInserter but without any indexing. A short while later, I added indexing using Cypher by doing this:

CREATE INDEX ON :MyLabel(myId)

NB: My original post linked each of the APIs mentioned below to the respective neo4j online documentation, but I cannot post more than two links because I'm a new user. All classes and methods below can be found here: http://api.neo4j.org/2.1.0-M02/allclasses-frame.html

Now I want to import many more relationships from an external source. All of the incoming relationship data contains references to myId of existing nodes. BatchInserter seems to be the way to go again, but the createRelationship method requires the node IDs.

I need to convert the incoming myIds to the node IDs of the database, and I want to leverage the index I created earlier. It looks like I need to use a BatchInserterIndex, which is provided using a BatchInserterIndexProvider. The only BatchInserterIndexProvider I can find is LuceneBatchInserterIndexProvider, but its nodeIndex method requires a "name".

This is where I'm stuck. What name do I give it? My earlier Cypher "CREATE INDEX ON" statement didn't show me a name, and I do not see a name when I do a ":schema" command in the shell. This is the entire output:

Indexes
  ON :MyLabel(myId) ONLINE

No constraints

How do I batch import using my existing schema index? Is the literal string ":MyLabel(myId)" the name I should pass in? Is there a different class or strategy I'm missing?

All of the examples I could find online either initialized the data and the index in the same run, or they created the index from code with a name they could use later.

Was it helpful?

Solution

Unfortunately you cannot use the batch-inserter with schema indexes (yet).

Do you use the plain batch-inserter APIs ?

Then I would recommend the following.

When you start your batch-insertion process: Iterate over all nodes of the db, get their node-id and their myId put both into a hashmap (or array) and use that to lookup the node-id for your relationship-insertion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top