Importing data in Neo4j

318 views
Skip to first unread message

Fares Bady

unread,
Sep 24, 2013, 7:23:32 AM9/24/13
to ne...@googlegroups.com
Hi,



I am writing this email to ask you whether there is a good tutorial that I could follow in order to import data that represent log file for access control into neo4j.

an example of the log file is attached to this email.

the idea the have is UserID, Role and ReaderID should be represented as noods but I dont know how the time should be represented. Should I represent as a part of the relationship between users and roles and having the permission to access the rooms?

Your help is highly appreciated.

regards
Fares
log file.xls

Bassman

unread,
Sep 24, 2013, 8:56:46 AM9/24/13
to ne...@googlegroups.com
I don't think Neo4J has an import facility (that would be nice; an odd omission...), but I recall seeing on post re: something similar to what you describe, which used Excel.  Here is the URL: http://blog.neo4j.org/2013/03/importing-data-into-neo4j-spreadsheet.html

The "trick" was to add one or more columns with formulas to create Cypher statements.  Basically, for each line of your spreadsheet, have a formula that creates the Cypher command(s).  I didn't read closely enough to see you you save the results to a text file, but presumably you do, then run the text file in the Neo4J shell.

 

Bassman

unread,
Sep 24, 2013, 9:01:09 AM9/24/13
to ne...@googlegroups.com
BTW, an "import" facility, and the ability to exchange GraphML and GEFX with Gephi and yED would be nice...

Gremlin (available in stable Neo4J versions) has limited ability to export GraphML (not so good for labels/properties).

Bassman

unread,
Sep 24, 2013, 9:05:44 AM9/24/13
to ne...@googlegroups.com
I see another post here talking about a "batch importer", available via Maven.  Maybe something is "in the works" which may eventually be included in Neo4J!

Michael Hunger

unread,
Sep 24, 2013, 9:18:14 AM9/24/13
to ne...@googlegroups.com
There are some docs around it linked here: http://www.neo4j.org/develop/import
I wrote some of these:


For the other tasks I added some neo4j-shell commands: https://github.com/jexp/neo4j-shell-tools


--
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.

Michael Hunger

unread,
Sep 25, 2013, 3:43:53 AM9/25/13
to ne...@googlegroups.com
In general your users and locations (rooms) can be nodes.

The relationship could be either generally :VISITED with the properties: role, time, readerid.

Or you have individual relationship-types for the different types of visits.

(user {id: 123, firstname:"Hanne",lastname:"Smith"})-[:VISITED {role:"visitor", time: "0900 AM", readerid: "room1" })->(location {name:"readingRoom"})

In 2.0 you can use a combination of MERGE and CREATE with Labels

MERGE (user:USER {id: 123, firstname:"Hanne",lastname:"Smith"}), (location:Location {name:"readingRoom"})
CREATE (user)-[:VISITED {role:"visitor", time: "0900 AM", readerid: "room1" })->(location)

If your visit is a more important entity you can create a node for the visit itself and link more information to it. Then you can also represent the time, e.g. as time-tree: 

In general for modeling check out this webinar: http://watch.neo4j.org/video/73485354
And the free graph databases ebook: http://graphdatabases.com

HTH

Michael

--
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.
<log file.xls>

Fares Bady

unread,
Sep 25, 2013, 4:39:20 AM9/25/13
to ne...@googlegroups.com
Dear Michael,

Many thanks for your replies which really helped me.

I will try to follow your comments and I am going to define the relationship generally :VISITED with the properties: role, time, readerid.

Once I have everything done I will make sure that I let you know about the outcome the I get. and I will also come back to you if I face any issue.

Your help is highly appreciated

Best regards
Fares


--
You received this message because you are subscribed to a topic in the Google Groups "Neo4j" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/neo4j/3-HzCIi2rO8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to neo4j+un...@googlegroups.com.

Michael Hunger

unread,
Sep 25, 2013, 4:41:59 AM9/25/13
to ne...@googlegroups.com
Just make sure to create a graph-model-document (aka. graph gist out of that and put it up for the competition) :)

Fares Bady

unread,
Sep 26, 2013, 3:24:55 AM9/26/13
to ne...@googlegroups.com
hi

Just a quick question
when I tried to write the following query I face one issue:

CREATE (user {userid: "123", firstname:"Hanne", lastname:" Smith"})-[:HAS]->(role {rolename: "visitor" }) –[:VISITS {cardreaderID: "R1", time: "0900 AM"}]->(location {name:"readingRoom"})

I can see the graph what I want three nodes which user hanna, the role visitior and the location reading room. I also see the two relationships has and visits, but I wonder why I can't see the property with the relation visits such as time and cardreaderID.

Regards
Farse

Peter Neubauer

unread,
Sep 26, 2013, 4:07:33 AM9/26/13
to Neo4j User
So,
http://console.neo4j.org/r/we4272 is doing just that and listing the properties on relationships?

/peter


G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

The graphgist challenge - show me your graph - http://www.neo4j.org/learn/graphgist_challenge
Let's do Malmö Startup X-Change on Fridays   - http://doodle.com/gmfwhexiyy8ivv4w  

Michael Hunger

unread,
Sep 26, 2013, 4:13:40 AM9/26/13
to ne...@googlegroups.com
The properties on relationships are not shown in the visualizations right now.

This will probably change in the future.

But you should be able to see the properties if you do cypher queries.

Michael

Fares Bady

unread,
Sep 26, 2013, 4:24:51 AM9/26/13
to ne...@googlegroups.com
Dear Michael,


Many thanks for your rapid reply. It is really clear now.

Thanks again

Regards
Fares

Fares Bady

unread,
Sep 26, 2013, 4:49:17 AM9/26/13
to ne...@googlegroups.com
Hi

I just came across this issue when I was trying to write different cypher queries. It seems that the relations are repeated twice. For example, the relation has and the relation visits will appear twice in the table while we have only one relation called has and another one called visits.
the example is here
Regards
Farse

Fares Bady

unread,
Sep 26, 2013, 6:19:36 AM9/26/13
to ne...@googlegroups.com
I want to say that a user Hanna has been to room1 first then to room2 after that she has been to room three

CREATE (location1 { name:"room1" }),(location2 { name:"room2" }),(location3 { name:"room3" }),(user1 { firstname:"Hanne",lastname:" Smith",userid:"123" }), user1-[:VISITS { role: 'visitor' , cardreaderID:"R1",time:"0900 AM" }]->location1, user1-[:VISITS { role: 'visitor' , cardreaderID:"R2",time:"1000 AM" }]->location2, user1-[:VISITS { role: 'visitor' , cardreaderID:"R3",time:"1100 AM" }]->location3

with the the above statement is just shows that the user Hanna has been to room1, room2 and room three but not in sequence

any idea how I can have this right? as you can see the time is different when Hanna visited every room.

Your help is highly appreciated

Fares

Michael Hunger

unread,
Sep 26, 2013, 6:37:43 AM9/26/13
to ne...@googlegroups.com
Your forgot a direction in your relationship pattern, so each rel will be matched twice once per direction:

MATCH visitor-[r]->() 
RETURN r

works better

You should use labels like I showed below:


MERGE (user:User {id: 123, firstname:"Hanne",lastname:"Smith"}), (location:Location {name:"readingRoom"})

Michael Hunger

unread,
Sep 26, 2013, 6:39:39 AM9/26/13
to ne...@googlegroups.com
If you want to place more importance on the visits, make them nodes then you can also connect them "in order" of their appearance.

See this datastructure for representing time and ordering: http://docs.neo4j.org/chunked/milestone/cypher-cookbook-path-tree.html

Michael

Fares Bady

unread,
Sep 26, 2013, 6:54:59 AM9/26/13
to ne...@googlegroups.com
do u mean that I should make the locations as nodes? I have already done this. but visit is a relations that maps roles to locations.

I think I might add a new relationship between locations to show the order of the locations. For example, room1-[NEXT]-> room2, room2-[NEXT]->room3

Is this what you meant?

Fares

Michael Hunger

unread,
Sep 26, 2013, 7:08:44 AM9/26/13
to ne...@googlegroups.com
I meant relationships between the visit event nodes to indicate the order.

Fares Bady

unread,
Sep 26, 2013, 7:15:50 AM9/26/13
to ne...@googlegroups.com
ic.

I have just written the following sataement

CREATE (user { userid: '123' , firstname:"Hanne", lastname:" Smith" })-[:HAS]->(role { rolename: 'visitor' })-[:VISITS { cardreaderID: 'R1' , time: '0900 AM' }]->(location { name:"readingRoom" })-[:NEXT { cardreaderID: 'R2' , time: '0920 AM' }]->(location1 { name: 'coffee' })

The graph looks fine to me I just need to think about more complex scenarios

http://console.neo4j.org/?id=nhwahf

Regards

TC

unread,
Apr 17, 2014, 8:07:07 PM4/17/14
to ne...@googlegroups.com
Hi, I have the similar question here.
While my data is just two part: startnode and endnode.
They don't have such label properties. Can they run on neo4j too? I didn't find a tutorial to follow.
Thanks

Alex Frieden

unread,
Apr 17, 2014, 9:36:42 PM4/17/14
to ne...@googlegroups.com
Any chance you can create a graphgist if you are using cypher or provide code if you are using the java api.  Thanks!


--
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/d/optout.



--
Alexander Frieden

Jim Webber

unread,
Apr 19, 2014, 8:03:50 AM4/19/14
to ne...@googlegroups.com
I echo this:

Hannah's visits are a linked list of things she's done. Each visit is -[:TO]-> a place. To find Hannah's visit history just means traversing the list.

Jim
Reply all
Reply to author
Forward
0 new messages