BH13.13/Cypher

提供:TogoWiki

移動: 案内, 検索

Cypher 例文集です。Annotation をしっかり書きましょう。

MATCH

  • 全てのノードを返す (全部レンダリングすると遅いのでlimitつける)
MATCH (n)
RETURN n
LIMIT 10
  • 全てのリレーションを返す
MATCH (n)-[r]-(t)
RETURN r
LIMIT 10
  • 有向グラフで構成要素を返す
MATCH (n)-[r]->(t)
RETURN n, r, t
LIMIT 10
  • ラベル・インデックスを使って返す
MATCH (n:nodeLabel)-[r:relLabel]->(t:nodeLabel)
RETURN n, r, t
LIMIT 10
  • パスを返す
MATCH p=(n:nodeLabel)-[r:relLabel]->(t:nodeLabel)
RETURN p
LIMIT 10
  • variable length paths
MATCH p=(n:nodeLabel)-[r:relLabel*0..3]->(t:nodeLabel)
RETURN p
LIMIT 10
  • プロパティでノードを指定する
MATCH p=(n:nodeLabel {name: "hoge"})-[r:relLabel*0..3]->(t:nodeLabel {name: "fuga"})
RETURN p
LIMIT 10
  • shortest path
MATCH hoge=(n:nodeLabel {name: "hoge"}), fuga=(t:nodeLabel {name: "fuga"}),
p=shortestPath((hoge)-[r:relLabel*0..10]->(fuga))
RETURN p
  • all shortest paths
MATCH hoge=(n:nodeLabel {name: "hoge"}), fuga=(t:nodeLabel {name: "fuga"}),
p=allShortestPaths((hoge)-[r:relLabel*]->(fuga))
RETURN p

WHERE

  • whereでちょっと凝ったフィルタ
MATCH (n:nodeLabel)-[r:relLabel]->(t:nodeLabel)
WHERE n.name = "hoge" OR n.name = "fuga"
RETURN n
  • whereでちょっと凝ったフィルタ
MATCH (n:nodeLabel)-[r:relLabel]->(t:nodeLabel)
WHERE NOT n.name = "hoge"
RETURN n
  • プロパティの有無でフィルタ
MATCH (n:nodeLabel)-[r:relLabel]->(t.nodeLabel)
WHERE HAS n.some_property
RETURN n
  • 値の大小
MATCH (n:nodeLabel) -[r:relLabel]->(t.nodeLabel)
WHERE n.int_property > 10
RETURN n
  • 正規表現最高
MATCH (n:nodeLabel) -[r:relLabel]->(t.nodeLabel)
WHERE n.name =~ 'hog.*'
RETURN n
  • リストを使う
MATCH (n:nodeLabel) -[r:relLabel]->(t.nodeLabel)
WHERE n.name IN ["hoge", "fuga"]
RETURN n 

DELETE

  • 全てのノードとリレーションシップを削除。手動付加の索引は削除されない。
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r
/mw/BH13.13/Cypher」より作成