Search code examples
neo4jneography

How to use "MATCH.. CREATE UNIQUE.." with neography


I'm trying to write an importer script that will take a MySQL resultset and add nodes and relationships in my Neo4J DB. To simplify things, my resultset has the following fields:

  • application_id
  • amount
  • application_date
  • account_id

I want to create a node with Application label with the application_id, amount, application_date fields and another node with Account label with account_id field and a relationship between them.

My SQL query is from the applications table so I'm not afraid of dups there, but an account_id can appear more than once and I obviously don't want to create multiple nodes for that.

I'm using neography (but willing to switch if there is something simpler). What would be the best (easiest) way to achieve that? My script will drop the database before it starts so no leftovers to take care of.

Should I create an index before and use create_unique_node?
I think I can do what I want in cypher using "MATCH .. CRAETE UNIQUE..", what's the equivalent of that in neography? I don't understand how index_name gets into the equation...
Should I or should I not define the constraint on Account?

Many thanks, It's my first time with graph DBs so apologies if I miss a concept here..


Solution

  • From what you describe, it looks like you should use the constraints that come with Neo4j 2.0 : http://docs.neo4j.org/chunked/milestone/query-constraints.html#constraints-create-uniqueness-constraint

    CREATE CONSTRAINT ON (account:ACCOUNT) ASSERT account.account_id IS UNIQUE

    Then you can use the MATCH .. CREATE UNIQUE clauses for all your inserts. You can use neography to submit the cypher queries, see the examples here: https://github.com/maxdemarzi/neography/wiki/Scripts-and-queries