Create Nodes and Relation with Transaction [Begin - Commit] inside Cypher Console - Error Message

445 views
Skip to first unread message

Filip W.

unread,
Jul 8, 2013, 9:55:40 AM7/8/13
to ne...@googlegroups.com
Hello,
I am following the Beer Post Method from the blog Neo4j.
So far i tested my Cypher query with my data in Neo4j Cypher Console.

But now i would like to import my nodes/edges in Neo4j on local Server and because with long cypher query on the Neo4j Console it bugs when your rquery is too big

I would like to use a Transaction with [Begin and Commit] to generate all nodes and edges.
But when i test with a dummy request picked from an exemple on the web (just before to use with my query) i got the below Error message

  • neo4j-sh (0)$ BEGIN CREATE (m{n:'m', d:'3'}), (f0{n:'f0', d:'2'}), m-[:so]->f0; commit exit
  • ==> Error: To open a transaction, write BEGIN TRANSACTION
So i try the same example with BEGIN TRANSACTION
  • neo4j-sh (0)$ BEGIN TRANSACTION CREATE (m{n:'m', d:'3'}), (f0{n:'f0', d:'2'}), m-[:so]->f0; commit exit
  • ==> Error: To open a transaction, write BEGIN TRANSACTION
But still the same problem...

Could someone tell me what is the right syntax to use this kind of transaction ?
Thank you.
Filip

Michael Hunger

unread,
Jul 8, 2013, 11:09:23 AM7/8/13
to ne...@googlegroups.com
Can you put each of those in on a new line? As those are individual commands? There is imho && as a delimeter between commands.

BEGIN
CREATE (m{n:'m', d:'3'}), (f0{n:'f0', d:'2'}), m-[:so]->f0; 
commit

This worked for me:

  • begin && start n=node(*) return n limit 1; && commit
  • ==> Transaction started
  • ==> +-----------+
  • ==> | n         |
  • ==> +-----------+
  • ==> | Node[0]{} |
  • ==> +-----------+
  • ==> 1 row
  • ==> 183 ms
  • ==> Transaction committed

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Filip W.

unread,
Jul 8, 2013, 11:32:35 AM7/8/13
to ne...@googlegroups.com
Hi Michael,

Let's say that my actually query for Cypher (i run it in Neo4j Online Console) is :

CREATE (Activity_1 { Name_Activity:'Activity_ACTUAL_RENTALS_FOR_HOUSING' } ),(John_1 { Name_Actor:'John',  Type:'Person' } ),(Television { Name:'Television', Type:'Device' } ),(House_John { Name:'House John', Type:'Location' } ),(Day { Day:'20', Type:'Day' } ),(Month { Month:'6', Type:'Month' } ),(Year { Year:'2013', Type:'Year' } ),(Hour { Hour:'4', Type:'Hour' } ),(Minute { Minute:'30', Type:'Minute' } ),(Second { Second:'0', Type:'Second' } ),(Longitude { Longitude:'0.11982', Type:'Longitude' } ),(Latitude { Latitude:'51.51121', Type:'Latitude' } ),(Timeline { Name:'Timeline', Type:'Timeline' } ), Activity_1-[:IS_PART]->ACTUAL_RENTALS_FOR_HOUSING, John_1-[:IS_PART]->Activity_1,John_1-[:USE]->Television, Television-[:To_Be_At]->House_John, John-[:To_Be_At]->Longitude, John-[:To_Be_At]->Latitude, Day-[:IS_DAY]->Month, Month-[:IS_MONTH]->Year, Year-[:IS_YEAR]->Timeline, Hour-[:IS_HOUR]->Day, Minute-[:IS_MINUTE]->Hour, Second-[:IS_SECOND]->Minute, Activity_1-[:OCCUR]->Second, Activity_1-[:HAS_LOCATION]->Longitude, Activity_1-[:HAS_LOCATION]->Latitude

So i have many like this over. At one point i need to put it in a transaction with Begin and Commit.
I used Excel to generate automatically the query above.

But i am not able to insert this kind of query in an Begin and Commit Transaction. Probably the syntax is not good.



Another issue for me,  is that for every activity where john is doing something different i need to create a different john node. like john_1, john_2 .... corresponding to the number of the involved activity. i decided (or was forced) to create a Entity john for every time he makes an action because Neo4j returned (if you just write everytime john) that john has already be created. Perhaps the way that i model and write the data in Neo4j is not accurate.
I am not sure that this last point is clear :)

Thank you

Michael Hunger

unread,
Jul 8, 2013, 12:17:05 PM7/8/13
to ne...@googlegroups.com
I would probably use the shell and import the file with the -f switch.

bin/neo4j-shell -f import.cql

I also just created a tool over the weekend that might help you.


Ping me if you have any questions.

Michael

Filip W.

unread,
Jul 8, 2013, 3:31:11 PM7/8/13
to ne...@googlegroups.com
Hey Michael,
Thank you for these information.
I was on the Neo4j Cypher workshop in Berlin that you gave (in March i think), so your information at this time were already helpful.
I will try your tool and let you now if i need some information.
Thank you,
Reply all
Reply to author
Forward
0 new messages