jpskill.com
🛠️ 開発・MCP コミュニティ

neo4j

Neo4jは、つながりのあるデータを扱うグラフデータベースで、Cypherクエリ言語やノードとリレーションシップのモデリング、グラフアルゴリズム、Node.jsとの連携などを習得し、データ間の関係性をビジネスに活用するSkill。

📜 元の英語説明(参考)

Neo4j is the leading graph database for connected data. Learn Cypher query language, node and relationship modeling, graph algorithms, and integration with Node.js using the official neo4j-driver.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Neo4jは、つながりのあるデータを扱うグラフデータベースで、Cypherクエリ言語やノードとリレーションシップのモデリング、グラフアルゴリズム、Node.jsとの連携などを習得し、データ間の関係性をビジネスに活用するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o neo4j.zip https://jpskill.com/download/15160.zip && unzip -o neo4j.zip && rm neo4j.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15160.zip -OutFile "$d\neo4j.zip"; Expand-Archive "$d\neo4j.zip" -DestinationPath $d -Force; ri "$d\neo4j.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して neo4j.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → neo4j フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Neo4j

Neo4j は、データをノードとリレーションシップ(エッジ)として格納するため、ソーシャルネットワーク、レコメンデーションエンジン、不正検出、ナレッジグラフに最適です。

インストール

# Docker (推奨)
docker run -d --name neo4j -p 7474:7474 -p 7687:7687 \
  -e NEO4J_AUTH=neo4j/password123 \
  neo4j:5

# ブラウザ UI へのアクセス: http://localhost:7474
# Bolt プロトコル: bolt://localhost:7687

# Node.js ドライバー
npm install neo4j-driver

# Python ドライバー
pip install neo4j

Cypher の基礎

// create-nodes.cypher: ラベルとプロパティを持つノードを作成します
CREATE (alice:Person {name: 'Alice', email: 'alice@example.com', age: 30})
CREATE (bob:Person {name: 'Bob', email: 'bob@example.com', age: 28})
CREATE (graphDb:Technology {name: 'Neo4j', category: 'Database'})
RETURN alice, bob, graphDb;
// create-relationships.cypher: 型付きのリレーションシップでノードを接続します
MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
CREATE (a)-[:KNOWS {since: 2024}]->(b)
RETURN a, b;

MATCH (a:Person {name: 'Alice'}), (t:Technology {name: 'Neo4j'})
CREATE (a)-[:USES {skill_level: 'expert'}]->(t)
RETURN a, t;

クエリ

// queries.cypher: 一般的なクエリパターン
// 友達の友達を見つける
MATCH (p:Person {name: 'Alice'})-[:KNOWS]->()-[:KNOWS]->(fof)
WHERE fof <> p
RETURN DISTINCT fof.name;

// 2人間の最短経路
MATCH path = shortestPath(
  (a:Person {name: 'Alice'})-[:KNOWS*..6]-(b:Person {name: 'Charlie'})
)
RETURN path, length(path);

// フィルタリングによるパターンマッチング
MATCH (p:Person)-[r:USES]->(t:Technology)
WHERE r.skill_level = 'expert'
RETURN p.name, collect(t.name) AS technologies;

// 集計
MATCH (p:Person)-[:KNOWS]->(friend)
RETURN p.name, count(friend) AS friend_count
ORDER BY friend_count DESC
LIMIT 10;

インデックスと制約

// indexes.cypher: パフォーマンス向上のためのインデックスと制約を作成します
CREATE CONSTRAINT person_email IF NOT EXISTS
  FOR (p:Person) REQUIRE p.email IS UNIQUE;

CREATE INDEX person_name IF NOT EXISTS
  FOR (p:Person) ON (p.name);

// 複合インデックス
CREATE INDEX order_status_date IF NOT EXISTS
  FOR (o:Order) ON (o.status, o.created_at);

// フルテキストインデックス
CREATE FULLTEXT INDEX person_search IF NOT EXISTS
  FOR (p:Person) ON EACH [p.name, p.bio];

CALL db.index.fulltext.queryNodes('person_search', 'Alice') YIELD node, score
RETURN node.name, score;

Node.js ドライバー

// db.js: 公式 Node.js ドライバーを使用した Neo4j クライアント
const neo4j = require('neo4j-driver');

const driver = neo4j.driver(
  'bolt://localhost:7687',
  neo4j.auth.basic('neo4j', 'password123')
);

async function findFriends(name) {
  const session = driver.session({ database: 'neo4j' });
  try {
    const result = await session.executeRead(tx =>
      tx.run(
        'MATCH (p:Person {name: $name})-[:KNOWS]->(friend) RETURN friend.name AS name',
        { name }
      )
    );
    return result.records.map(r => r.get('name'));
  } finally {
    await session.close();
  }
}

async function createFriendship(person1, person2) {
  const session = driver.session({ database: 'neo4j' });
  try {
    await session.executeWrite(tx =>
      tx.run(
        `MERGE (a:Person {name: $p1})
         MERGE (b:Person {name: $p2})
         MERGE (a)-[:KNOWS]->(b)`,
        { p1: person1, p2: person2 }
      )
    );
  } finally {
    await session.close();
  }
}

// 終了時のクリーンアップ
process.on('exit', () => driver.close());

module.exports = { findFriends, createFriendship };

Python ドライバー

# app.py: 公式 Python ドライバーを使用した Neo4j
from neo4j import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password123"))

def find_friends(name):
    with driver.session() as session:
        result = session.run(
            "MATCH (p:Person {name: $name})-[:KNOWS]->(f) RETURN f.name AS name",
            name=name,
        )
        return [record["name"] for record in result]

def recommend_friends(name):
    with driver.session() as session:
        result = session.run("""
            MATCH (p:Person {name: $name})-[:KNOWS]->(friend)-[:KNOWS]->(rec)
            WHERE NOT (p)-[:KNOWS]->(rec) AND rec <> p
            RETURN rec.name AS name, count(*) AS mutual
            ORDER BY mutual DESC LIMIT 5
        """, name=name)
        return [dict(r) for r in result]

driver.close()

グラフデータモデリングのヒント

モデリングのガイドライン:
- 名詞 → ノードラベル (Person, Product, Order)
- 動詞 → リレーションシップタイプ (PURCHASED, KNOWS, REVIEWED)
- 形容詞 → ノードまたはリレーションシップのプロパティ
- 常に方向性を持たせる: (a)-[:KNOWS]->(b)。クエリは -[:KNOWS]- で方向を無視できます
- スーパーノード(数百万のリレーションシップ)は避ける。中間ノードを使用する
- 重み、タイムスタンプ、メタデータにはリレーションシッププロパティを使用する
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Neo4j

Neo4j stores data as nodes and relationships (edges), making it ideal for social networks, recommendation engines, fraud detection, and knowledge graphs.

Installation

# Docker (recommended)
docker run -d --name neo4j -p 7474:7474 -p 7687:7687 \
  -e NEO4J_AUTH=neo4j/password123 \
  neo4j:5

# Access browser UI at http://localhost:7474
# Bolt protocol at bolt://localhost:7687

# Node.js driver
npm install neo4j-driver

# Python driver
pip install neo4j

Cypher Basics

// create-nodes.cypher: Create nodes with labels and properties
CREATE (alice:Person {name: 'Alice', email: 'alice@example.com', age: 30})
CREATE (bob:Person {name: 'Bob', email: 'bob@example.com', age: 28})
CREATE (graphDb:Technology {name: 'Neo4j', category: 'Database'})
RETURN alice, bob, graphDb;
// create-relationships.cypher: Connect nodes with typed relationships
MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'})
CREATE (a)-[:KNOWS {since: 2024}]->(b)
RETURN a, b;

MATCH (a:Person {name: 'Alice'}), (t:Technology {name: 'Neo4j'})
CREATE (a)-[:USES {skill_level: 'expert'}]->(t)
RETURN a, t;

Querying

// queries.cypher: Common query patterns
// Find friends of friends
MATCH (p:Person {name: 'Alice'})-[:KNOWS]->()-[:KNOWS]->(fof)
WHERE fof <> p
RETURN DISTINCT fof.name;

// Shortest path between two people
MATCH path = shortestPath(
  (a:Person {name: 'Alice'})-[:KNOWS*..6]-(b:Person {name: 'Charlie'})
)
RETURN path, length(path);

// Pattern matching with filtering
MATCH (p:Person)-[r:USES]->(t:Technology)
WHERE r.skill_level = 'expert'
RETURN p.name, collect(t.name) AS technologies;

// Aggregation
MATCH (p:Person)-[:KNOWS]->(friend)
RETURN p.name, count(friend) AS friend_count
ORDER BY friend_count DESC
LIMIT 10;

Indexes and Constraints

// indexes.cypher: Create indexes and constraints for performance
CREATE CONSTRAINT person_email IF NOT EXISTS
  FOR (p:Person) REQUIRE p.email IS UNIQUE;

CREATE INDEX person_name IF NOT EXISTS
  FOR (p:Person) ON (p.name);

// Composite index
CREATE INDEX order_status_date IF NOT EXISTS
  FOR (o:Order) ON (o.status, o.created_at);

// Full-text index
CREATE FULLTEXT INDEX person_search IF NOT EXISTS
  FOR (p:Person) ON EACH [p.name, p.bio];

CALL db.index.fulltext.queryNodes('person_search', 'Alice') YIELD node, score
RETURN node.name, score;

Node.js Driver

// db.js: Neo4j client with official Node.js driver
const neo4j = require('neo4j-driver');

const driver = neo4j.driver(
  'bolt://localhost:7687',
  neo4j.auth.basic('neo4j', 'password123')
);

async function findFriends(name) {
  const session = driver.session({ database: 'neo4j' });
  try {
    const result = await session.executeRead(tx =>
      tx.run(
        'MATCH (p:Person {name: $name})-[:KNOWS]->(friend) RETURN friend.name AS name',
        { name }
      )
    );
    return result.records.map(r => r.get('name'));
  } finally {
    await session.close();
  }
}

async function createFriendship(person1, person2) {
  const session = driver.session({ database: 'neo4j' });
  try {
    await session.executeWrite(tx =>
      tx.run(
        `MERGE (a:Person {name: $p1})
         MERGE (b:Person {name: $p2})
         MERGE (a)-[:KNOWS]->(b)`,
        { p1: person1, p2: person2 }
      )
    );
  } finally {
    await session.close();
  }
}

// Cleanup on exit
process.on('exit', () => driver.close());

module.exports = { findFriends, createFriendship };

Python Driver

# app.py: Neo4j with official Python driver
from neo4j import GraphDatabase

driver = GraphDatabase.driver("bolt://localhost:7687", auth=("neo4j", "password123"))

def find_friends(name):
    with driver.session() as session:
        result = session.run(
            "MATCH (p:Person {name: $name})-[:KNOWS]->(f) RETURN f.name AS name",
            name=name,
        )
        return [record["name"] for record in result]

def recommend_friends(name):
    with driver.session() as session:
        result = session.run("""
            MATCH (p:Person {name: $name})-[:KNOWS]->(friend)-[:KNOWS]->(rec)
            WHERE NOT (p)-[:KNOWS]->(rec) AND rec <> p
            RETURN rec.name AS name, count(*) AS mutual
            ORDER BY mutual DESC LIMIT 5
        """, name=name)
        return [dict(r) for r in result]

driver.close()

Graph Data Modeling Tips

Modeling Guidelines:
- Nouns → Node labels (Person, Product, Order)
- Verbs → Relationship types (PURCHASED, KNOWS, REVIEWED)
- Adjectives → Properties on nodes or relationships
- Always direction: (a)-[:KNOWS]->(b), query can ignore direction with -[:KNOWS]-
- Avoid super-nodes (millions of relationships); use intermediate nodes
- Use relationship properties for weight, timestamp, metadata