In Neo4j, I have a person node, company node and a position node. So, a "person" has a "position" at a "company". I have a question about modelling the database and the relationships between these nodes.
I could set it up like this (cypher "pseudo code"):
(person)-[:WORKS_AT]-(company)
(person)-[:HAS_TITLE]->(position)
(company)-[:HAS_POSITION]->(position)
person has relationship HAS_TITLE and WORKS_AT, or like this:
(person)-[:HAS_TITLE]->(position)<-[:HAS_POSITION]-(company)
where there is no direct relationship between the person and the company, I will have to go through the position node to find the company.
I guess it depends a little bit of what I want to get out of the database, but is there a "correct/standard" way of doing this in a graph database?
Edit:
When searching in the database I want to get all the positions for a person. I want to return them as a collection like this:
[
{
company: 'some company',
position: 'some position at the company'
},
{
company: 'some other company',
position: '' // empty position, I dont have the position data here
} ,
{
company: 'some other company',
position: 'some position at the company'
}
]
Edit 2:
To clarify a little bit: this is the data structure I get to work with (json). This is data for one person only, there are multiple people who can have the same position in different companies etc. I need to put it into Neo4j and make it searchable:
{
"id": 123,
"name": "Foo Bar",
"email": "",
"workhistory": {
"positions": [
{
"company": "Company A",
"employees": "",
"type": "Privately Held",
"start": 1356998400,
"end": "",
"position": "Position A",
"description": "",
"industry": "some industry"
},
{
"company": "Company B",
"employees": "",
"type": "Privately Held",
"start": 1356998400,
"end": "",
"position": "Position B",
"description": "",
"industry": "some industry"
},
{
"company": "Company C",
"employees": "",
"type": "Privately Held",
"start": 1341100800,
"end": "",
"position": "Position A",
"description": "",
"industry": ""
}
]
}
}
I want to be able to search for a "position" node with a "name" property called "Position A", then find all the people with this position and return their profile with the same structure it had when it was put into the database, give or take.
Same goes for "industry" and "company", I want to break those off into separate nodes as well. The database will have millions of people in it.
Edit 3
I'm thinking of maybe adding the position as a node, with a "name" property etc. And then also add the position name on the relationship from person to company. This will make it easy to query for work history, but will take extra space for each WORKED_AT relationship (the WORKED_AT.position property). With this structure I can do searches on a position node as well, and get all the people related to a certain position.
This will probably be ok for this easy structure, but then what about more "nested" values? Like Person lives in City located in State located in Country etc?