Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-30-2020 06:05 AM
I have a dataset of the list of employees working for a company, the dataset consists of different columns. I had loaded this dataset in neo4j idle using cypher query. I had created nodes and relationships between rows and columns.
my cypher query
:auto USING PERIODIC COMMIT 5
LOAD CSV WITH HEADERS FROM 'file:///y.csv' AS line
merge (jm:JM {employjoining:line.MonthNamofJoining})
merge (jy:JY {employjoiningyear:line.YearofJoining})
merge (id:ID {Employe_ID:line.EmpID})
merge (fn:FN {Employfirstname:line.FirstName})
merge (ln:LN {Employlastname:line.LastName})
merge (g:G {gender:line.Gender})
merge (id)-[:Gender]->(g)-[:FirstName]->(fn)-[:LastName]->(ln)-[:MonthNamofJoining]->(jm)-[:YearofJoining]->(jy)
RETURN id,g,fn,ln,jm,jy limit 10
i am new to neo4j i tried very hard to find relationships between nodes. But i failed manytimes in retrieving data. i tried some cypher queries but not able to get exact output. please help me writing cypher queries to below cases
12-30-2020 10:29 AM
You are creating a node for each employee property. Instead, you should model them as node properties. Create an Employee node add these properties. Here is the Cypher:
MERGE (a:Employee {empid:line.EmpID, firstname:line.FirstName, lastname:line.LastName, gender:line.Gender, joiningMonth:toInteger(ine.MonthNamofJoining), joiningYear:toInteger(line.YearofJoining)})
Here you are creating Employee nodes and they are not connected to each other.
Run this query to get all Employee nodes with joining year = 2020
MATCH (c:Employee)
WHERE c.joiningYear = 2020
12-30-2020 08:14 PM
Thank you. But I want to know all common properties shared by any two employees
I want a similar relationship shared with one employee node to other employees in the dataset (example in terms of joining month, year, location, etc.). for example, from the list of employees, i had selected one employee as interest and I want to know how other employees are similar to that employee
Thank you
12-30-2020 09:05 PM
Here is another way:
Created Year and Month nodes and connected them to Employee node. Here is the Cypher:
MERGE (y:Year {year:toInteger(line.YearofJoining)})
MERGE (m:Month {month:line.MonthNamofJoining)})
MERGE (y)-[:MONTH]->(m)
MERGE (a:Employee {empid:line.EmpID, firstname:line.FirstName, lastname:line.LastName, gender:line.Gender})
MERGE (m)-[:EMPLOYEE]->(a)
Get all the employees employed in December 2020:
MATCH (y:Year)-[:MONTH]->(m:Month)-[:EMPLOYEE]->(e:Employee)
WHERE y.year = 2020, m.month = "December"
RETURN y, m, e
Get employees with last name = "Doe":
MATCH (e:Employee)
WHERE e.lastname = "Doe"
RETURN e
Like this you can combine many properties and get employees that match the selected filters.
01-01-2021 08:56 PM
Hi, This query is throwing a syntax error bwtween where y.year=2020 , m.month='December'
01-01-2021 09:08 PM
WHERE y.year = 2020, m.month = "December"
should be:
WHERE y.year = 2020 AND m.month = "December"
01-01-2021 09:42 PM
Get two employees list
MATCH (e:Employee)-[:EMPLOYEE]->(y:Year)-[:MONTH]->(m:Month)
WHERE e.empid = "829478" AND e.empid = "940813"
RETURN y, m,e
Here i want to return all relationships and nodes for above two employee id's
But showing the result no changes , no records
how can i get relationships between two nodes
01-02-2021 11:02 AM
This AND
expression will always be FALSE:
WHERE e.empid = "829478" AND e.empid = "940813"
Better is to use IN a list, as you can easily expand or contract the number of ids:
WHERE e.empid IN ["829478", "940813"]
Also, you may want to convert your empid
s to integers. They are more compact and faster.
MATCH(e:Employee)
WHERE exists(e.empid) // this isn't necessary since toInteger(null) is null
set e.empid = toInteger(e.empid)
01-03-2021 09:26 PM
MATCH p = (y:Year)-[:MONTH]->(m:Month)-[:EMPLOYEE]->(e:Employee)
WHERE e.empid IN ["858541", "128466"]
return p
Here i want to return all relationships and nodes for above two employee id's
But showing the result no changes , no records
how can i get relationships between two nodes
01-04-2021 08:18 AM
You need to debug this step by step.
First try this:, to see if you get the two employees back.
MATCH p = (e:Employee)
WHERE e.empid IN ["858541", "128466"]
return p
Then try this:, to see if you get the two employees back and the month
MATCH p = (m:Month)-[:EMPLOYEE]->(e:Employee)
WHERE e.empid IN ["858541", "128466"]
return p
etc.
I suspect that you have a typo or having missing data or something...
01-04-2021 09:28 PM
Thank you, I tried to build a graph model using data, here is the cypher query
MERGE (a:Employee {empid:line.EmpID, firstname:line.FirstName,
lastname:line.LastName})
MERGE (g:gen{gender:line.Gender})
MERGE (y:Year {year:toInteger(line.YearofJoining)})
MERGE (m:Month {month:line.MonthNamofJoining})
MERGE (ag:Age {age:line.AgeinYrs})
MERGE (wt:Weight{weight:line.WeightinKgs})
MERGE (c:City {city:line.City,pincode:line.PinCode})
MERGE (ct:County {county:line.County})
MERGE (es:State {state:line.State})
MERGE (er:Region {region:line.Region})
MERGE ()-[:EMPLOYEE]->(a)-[:GENDER]->(g)-[:AGE]->(ag)-[:WEIGHT]->(wt)-[:CITY]->
(c)-[:COUNTY]-(ct)-[:STATE]->(es)-[:REGION]->(er)-[:YEAR]->(y)-[:MONTH]->(m)
I need to return all connecting path, so i tried below query
MATCH p = ()-[:EMPLOYEE]->(a)-[:GENDER]->(g)-[:AGE]->(ag)-[:WEIGHT]->(wt)-
[:CITY]->(c)-[:COUNTY]->(ct)-[:STATE]->(es)-[:REGION]->(er)-[:YEAR]->(y)-[:MONTH]->
(m)
WHERE a.empid IN ["858541", "128466"]
return p limit 25
But the result i got correct but there are many unnecessary paths. i am uploading the resulted graph please check and correct where i am doing wrong.
Thanks in advance
01-05-2021 01:03 AM
MERGE (g:gen{gender:line.Gender})
MERGE (y:Year {year:toInteger(line.YearofJoining)})
MERGE (m:Month {month:line.MonthNamofJoining})
MERGE (ag:Age {age:line.AgeinYrs})
MERGE (wt:Weight{weight:line.WeightinKgs})
Gender is kinda of ok. But individual nodes for others ?
Month is 12 nodes, Year can be anything, and for each year you have a month relationship. Age is an integer, with any number. Weight is a float and it can be so many ... example 10kg, 10.1kg 10.01 kg, all individual nodes. is there a reason ???
To answer your question about so many relationship is because, in your data there are other "Male" with "Age" 44. There are other people in "TX" who reside in "South".
You should convert the nodes into properties.
01-05-2021 01:56 AM
what are the nodes should I convert into properties?
01-05-2021 03:37 AM
share the full header file with description.
All the sessions of the conference are now available online