egman24
3/23/2016 - 1:04 AM

Cypher Query Language

Cypher Query Language

Cypher

Humane (optimised for reading) pattern matching query language for graphs.

http://neo4j.com/docs/stable/cypher-query-lang.html

http://neo4j.com/docs/stable/cypher-refcard/

Patterns
  • Node

    • (n)
  • Labels

    • (n:Label)
  • Properties

    • (n {name: {value}})
  • Relationships

    • directional (n)-->(m), (n)<--(m)
    • non directional (n)--(m)
Clauses
  • START | RETURN
    • https://youtu.be/NeJHRpbIqV0?t=492
    • START <lookup> RETURN <expressions>
    • START binds terms with simple lookup (directly using known ids, or based on indexed Property)
    • RETURN expressions specify result set
  • aggregation
    • https://youtu.be/NeJHRpbIqV0?t=570
    • in SQL (group by)
    • whenever you use grouping expressing in statement, then all the non grouped elements of the statement will be used to define the aggregation column
    • count(*) is example of aggregation statement
  • MATCH
    • https://youtu.be/NeJHRpbIqV0?t=658
    • START <lookup> MATCH <pattern> RETURN <expressions>
    • describes a pattern of nodes and relationships
      • node terms in optional parenthesis
      • lines with arrows for relationships
  • WHERE
    • https://youtu.be/NeJHRpbIqV0?t=747
    • very similar to SQL
    • START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expression>
    • filters nodes or relationships
      • uses expression to constrain elements
  • CREATE
    • https://youtu.be/NeJHRpbIqV0?t=815
    • Cypher not just for reading, also for updating the graph
    • can create nodes and relationships
      • create nodes with optional properties
      • create relationship (must have a type)
    • CREATE UNIQUE: creates graph if not there... if it is there, leaves it untouched
    • CREATE <node> [,node or relationship] RETURN <expression>
  • SET
    • https://youtu.be/NeJHRpbIqV0?t=851
    • set property or delete | update a property on node or relationship
      • must follow a start
    • SET [<node property>][<relationship property>]
  • DELETE
    • https://youtu.be/NeJHRpbIqV0?t=872
    • delete a node, relationship or property
      • must follow a START
      • to delete a node, all relationships must be deleted first
        • because of graph database constraint... no broken links
    • DELETE [<node>|<relationship>|<property>]
  • SKIP | LIMIT