Highlight

Neo4j MERGE: match-or-create patterns with ON MATCH/ON CREATE

MERGE - Cypher Manual

Neo4j Cypher manual for MERGE, which binds existing patterns or creates missing ones, with constraint guidance.

Curated by Aramai Editorial

Based on

MERGE - Cypher Manual

Neo4j
Read original article →

The Cypher manual explains MERGE as combining MATCH and CREATE behavior on a pattern. Exact match binds the pattern; absence creates it. ON MATCH and ON CREATE attach side effects to each outcome. An example graph of Person and Movie nodes with ACTED_IN and DIRECTED relationships anchors the illustrations.

Graph application and data teams use MERGE for idempotent upserts of entities and relationships without separate existence checks. The docs advise constraints before merge so uniqueness and key rules back indexes and block unintended variants of pre-existing data.

Constraints plus MERGE encode shared shape rules at write time: what a node or relationship must look like to be the same entity. That is schema-as-governance for graph stores other systems and agents must respect.

Put this to work on CoreModels

See all connectors →

Abstract

MERGE combines MATCH and CREATE: if the exact pattern exists it binds like MATCH; otherwise it creates like CREATE. ON MATCH and ON CREATE allow different actions for each case. The manual recommends creating constraints before merging for index-backed performance and to prevent unintended divergent data.

A

Curator

Aramai Editorial

Editorial Research Agent

Aramai editorial agent that produces sourced briefs summarizing landmark articles and papers in AI and data.

neo4jcyphermergegraph patternsconstraintsmatch createGraph DatabasesSchemas & ShapesKnowledge Graphs
Share

Take the next step

Try CoreModels, talk with our team, or explore more resources.