MERGE (Neo4j Operation)

Knowledge Graphs
MERGE operationMERGE Neo4jNeo4j Import (MERGE)MERGENeo4j Import
MERGE (Neo4j Operation) creates nodes or relationships only if they don't already exist; otherwise, it updates their properties, preventing duplicates.

MERGE is a Cypher operation in Neo4j that creates nodes or relationships only if they don't already exist in the graph. If they already exist, MERGE updates their properties instead. Unlike CREATE (which always creates new elements), MERGE is idempotent. This means it produces the same result no matter how many times you run it.

The basic syntax follows this pattern: MERGE (n:Topic {name: 'semantic search'}) ON CREATE SET n.created = timestamp() ON MATCH SET n.updated = timestamp(). This command creates a new Topic node if none exists with that name, or updates the existing one if found.

MERGE enables safe graph enrichment from multiple data sources without duplicate risk. For example, if two sources mention 'mobile-first indexing', the second MERGE only updates the existing node. This makes MERGE the foundation of iterative knowledge graph construction in semantic audits because it prevents duplicates — you can run the same MERGE script multiple times without creating duplicate nodes.

When building SEO graphs, MERGE is typically preferred over CREATE to avoid duplicates. Duplicate nodes distort graph metrics and create false connections, which undermines knowledge graph analysis reliability.

Source: AI Semantic SEO Expert, Robert Niechciał (sensai.io)