Neo4j graph modelling performance and querability, property to a node or as separate node plus relationship

Raf

I am teaching myself graph modelling and use Neo4j 2.2.3 database with NodeJs and Express framework.

I have skimmed through the free neo4j graph database book and learned how to model a scenario, when to use relationship and when to create nodes, etc.

I have modelled a vehicle selling scenario, with following structure

NODES

(:VEHICLE{mileage:xxx, manufacture_year: xxxx, price: xxxx})
(:VFUEL_TYPE{type:xxxx}) x 2 (one for diesel and one for petrol)
(:VCOLOR{color:xxxx}) x 8 (red, green, blue, .... yellow) 
(:VGEARBOX{type:xxx}) x 2 (AUTO, MANUAL) 

RELATIONSHIPS

(vehicleNode)-[:VHAVE_COLOR]->(colorNode - either of the colors)
(vehicleNode)-[:VGEARBOX_IS]->(gearboxNode - either manual or auto)
(vehicleNode)-[:VCONSUMES_FUEL_TYPE]->(fuelNode - either diesel or petrol)

Assuming we have the above structure and so on for the rest of the features. enter image description here

As shown in the above screenshot (136 & 137 are VEHICLE nodes), majority of the features of a vehicle is created as separate nodes and shared among vehicles with common feature with relationships.

Could you please advise whether roles (labels) like color, body type, driving side (left drive or right drive), gearbox and others should be seperate nodes or properties of vehicle node? Which option is more performance friendly, and easy to query?

I want to write a JS code that allows querying the graph with above structure with one or many search criteria. If majority of those features are properties of VEHICLE node then querying would not be difficult:

MATCH (v:VEHICLE) WHERE v.gearbox = "MANUAL" AND v.fuel_type = "PETROL" AND v.price > x AND v.price < y AND .... RETURN v; 

However with existing graph model that I have it is tricky to search, specially when there are multiple criteria that are not necessarily a properties of VEHICLE node but separate nodes and linked via relationship.

Any ideas and advise in regards to existing structure of the graph to make it more query-able as well as performance friendly would be much appreciated. If we imagine a scenario with 1000 VEHICLE nodes that would generate 15000 relationship, sounds a bit scary and if it hits a million VEHICLE then at most 15 million relationships. Please comment if I am heading in the wrong direction.

Thank you for your time.

FrobberOfBits

Modeling is full of tradeoffs, it looks like you have a decent start.

Don't be concerned at all with the number of relationships. That's what graph databases are good at, so I wouldn't be too concerned about over-using them.

Should something be a property, or a node? I can't answer for your scenario, but here are some things to consider:

  • If you look something up by a value all the time, and you have many objects, it's usually going to be faster to find one node and then everything connected to it, because graph DBs are good at exploiting relationships. It's less fast to scan all nodes of a label and find the items where a property=a value.
  • Relationships work well when you want to express a connection to something that isn't a simple primitive data type. For example, take "gearbox". There's manuals, and other types...if it's a property value, you won't later easily be able to decide to store 4 other sub-types/sub-aspects of "gearbox". If it were a node, that would later be easy because you could add more properties to the node, or relate other things.
  • If a piece of data really is a primitive (String, integer, etc) and you don't need extra detail about it, that usually makes a good property. Querying primitive values by connecting to other nodes will seem clunky later on. For example, I wouldn't model a person with a "date of birth" as a separate node, that would be irritating to query, and would give you flexibility you'd be very unlikely to need in the future.
  • Semantically, how is your data related? If two items are similar because they share an X, then that X probably should be a node. If two items happen to have the same Y value but that doesn't really mean much, then Y is probably better off as a node property.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Neo4j graph modelling performance and querability, property to a node or as separate node plus relationship

From Dev

Modelling a graph with classes 'edge' and 'node'

From Dev

Get property of neo4j node with optional relationship like left join

From Dev

Neo4j Creating a relationship conditionally based on one of the property of node

From Dev

How can i add property on returning node depending upon relationship exist or not in NEO4J

From Dev

Neo4J - Which is better to store element as a property of user or as a node & relationship?

From Dev

Read a property of a node in neo4j

From Dev

create relationship and merge node in loop in neo4j

From Dev

How to find node with no incoming relationship in neo4j

From Dev

Return value after deleting node or relationship in neo4j

From Dev

neo4j single node maximum relationship capacity

From Dev

neo4j - labels vs properties vs relationship + node

From Dev

Get node or relationship by ID in Neo4j embedded java

From Dev

Filter Neo4j nodes that have no relationship with a certain node

From Dev

Neo4j/Cypher delete node and childs with relationship

From Dev

Neo4j match nodes that are in relationship with one OR another node

From Dev

Relationship that connect the same node in Neo4j

From Dev

neo4j "try" to create relationship to node

From Dev

Relationship that connect the same node in Neo4j

From Dev

neo4j finding a node to create a relationship

From Dev

Neo4j node and relationship size on a single instance

From Dev

Neo4j - Cypher node and relationship relation

From Dev

Get full graph that node N is a part of in neo4j

From Dev

Neo4j graph algorithm / Node similarity

From Dev

create a node in neo4j graph db with transaction endpoint

From Dev

neo4j return 1 node with maximum property value

From Dev

Find node with maximal (minimal) values of property in Neo4j

From Dev

Store dynamic array in a Neo4J node property

From Dev

how to add a property to existing node neo4j cypher?

Related Related

  1. 1

    Neo4j graph modelling performance and querability, property to a node or as separate node plus relationship

  2. 2

    Modelling a graph with classes 'edge' and 'node'

  3. 3

    Get property of neo4j node with optional relationship like left join

  4. 4

    Neo4j Creating a relationship conditionally based on one of the property of node

  5. 5

    How can i add property on returning node depending upon relationship exist or not in NEO4J

  6. 6

    Neo4J - Which is better to store element as a property of user or as a node & relationship?

  7. 7

    Read a property of a node in neo4j

  8. 8

    create relationship and merge node in loop in neo4j

  9. 9

    How to find node with no incoming relationship in neo4j

  10. 10

    Return value after deleting node or relationship in neo4j

  11. 11

    neo4j single node maximum relationship capacity

  12. 12

    neo4j - labels vs properties vs relationship + node

  13. 13

    Get node or relationship by ID in Neo4j embedded java

  14. 14

    Filter Neo4j nodes that have no relationship with a certain node

  15. 15

    Neo4j/Cypher delete node and childs with relationship

  16. 16

    Neo4j match nodes that are in relationship with one OR another node

  17. 17

    Relationship that connect the same node in Neo4j

  18. 18

    neo4j "try" to create relationship to node

  19. 19

    Relationship that connect the same node in Neo4j

  20. 20

    neo4j finding a node to create a relationship

  21. 21

    Neo4j node and relationship size on a single instance

  22. 22

    Neo4j - Cypher node and relationship relation

  23. 23

    Get full graph that node N is a part of in neo4j

  24. 24

    Neo4j graph algorithm / Node similarity

  25. 25

    create a node in neo4j graph db with transaction endpoint

  26. 26

    neo4j return 1 node with maximum property value

  27. 27

    Find node with maximal (minimal) values of property in Neo4j

  28. 28

    Store dynamic array in a Neo4J node property

  29. 29

    how to add a property to existing node neo4j cypher?

HotTag

Archive