An approach to parsing the query.log

When one has enabled query.log through Neo4j Enterprise parameter dbms.logs.query.enabled the included bash shell script can be used to quickly parse the log and identify the top 10 most expensive queries based upon total execution time and if one has… Read more →

Resetting query cardinality

As queries execute, they build up result rows. Cypher executes operations per-row. When a query is made up of completely separate parts, unrelated to each other, and you don’t want to split the single query into multiple queries, you sometimes… Read more →

Tuning Cypher queries by understanding cardinality

Cardinality issues are the most frequent culprit in slow or incorrect Cypher queries. Because of this, understanding cardinality, and using this understanding to manage cardinality issues, is a critical component in Cypher query tuning, and query correctness in general. A… Read more →

Updating a node but returning its state from before the update

Some use cases require updating node (or relationship) properties, but returning the node (or relationship) as it was prior to the update. You’ll need to get a ‘snapshot’ of the node before the update, and return that snapshot instead of… Read more →

Creating and working with linked lists in Cypher

At some point when working with a graph, you may want to create a linked list out of some nodes. If each of the nodes to be linked has its own variable, this is easy, you just do a CREATE… Read more →

Conditional Cypher Execution

At some point you’re going to write a Cypher query requiring some conditional logic, where you want different Cypher statements executed depending on the case. At this point in time Cypher does not include native conditional functionality to address this… Read more →

Alternatives to UNION queries

While UNIONs can be useful for certain cases, they can often be avoided completely with small changes to the query. In this article we’ll present various example cases where a UNION isn’t necessary, and a simple Cypher query will do.… Read more →

Using AWS CLI to upload/download files to Amazon S3 bucket

If one has installed the AWS CLI To download a file from a S3 bucket anonymously run aws s3 cp s3://<AWS instance name>/<bucket_Name>/<file> <file> –no-sign-request and/or to upload to a Neo4j S3 buck anonymously run aws s3 cp <file> s3://<AWS… Read more →

How to log to neo4j.log in a Server Plugin

As part of the major changes in 3.0, the way to log to the user log, now neo4j.log (in server mode), has changed. To log within a Server Plugin follow these steps: Include these packages: import org.neo4j.logging.Log; import org.neo4j.logging.LogService; import… Read more →

Linux Out of Memory killer

The Out Of Memory Killer or OOM Killer is a process that the linux kernel employs when the system is critically low on memory. This situation occurs because the linux kernel has over allocated memory to its processes. When a… Read more →

How do I configure init and max java heap when running bin/neo4j-backup

When running $NEO4J_HOME/bin/neo4j-backup if a Java out of heap/memory error occurs you may want define the init and max Java heap to be used by neo4j-backup. The default behavior is to allow the JVM to define the init and max… Read more →

Understanding transaction and lock timeouts

One way to handle runaway queries is to impose a time limit that will terminate a query when exceeded. There are some subtleties here that need to be understood to ensure proper behavior and avoid confusion. Defining a transaction timeout… Read more →

How to import a file with LOAD CSV that has a space in file name?

When you try to import data from a file using LOAD CSV where the filename containing spaces for example you get the following error: Statement: load csv from “file:///test copy.csv” as row return row Error: Illegal character in path… Read more →

Useful Cypher statements for suspending and reactivating users

Commencing with Neo4j 3.1 and implementaion of native database users it is possible to suspend a user, thus preventing the user from further authenticating in. To view all suspended users run the following Cypher call yield username, flags with… Read more →

Enabling GC Logging

What is Garbage collection and why enabling it? A garbage collection event is a complete pause of the java application (ie: neo4j-server). It can be identified in the debug.log as a stop-the-world event. For example: If you notice issues with… Read more →

How do I quickly identify long gc pauses via the messages or debug logs

Java Garbage Collection (gc) pauses are monitored by the MonitorGc process in Neo4j, and recorded in the $NEO4J_HOME/logs/debug.log ( or $NEO4J_HOME/data/graph.db/messages.log for Neo4j v2.3.x and prior). To quickly find the 10 longest pauses in Neo4j 3.0 through Neo4j 3.3 one… Read more →

How do I quickly switch between multiple graphs without modifying neo4j.conf?

If you have multiple graphs set up and want to quickly switch between each without modifying dbms.active_database in conf/neo4j.conf, you can accomplish this with a neo4j restart and with the environment variable NEO4J_CONF defined pointing to the appropriate/corresponding neo4j.conf file.… Read more →

How to log to neo4j.log in an Unmanaged Extension

As part of the major changes in 3.0, the way to log to the user log, now neo4j.log (in server mode), has changed. To log within an Unmanaged Extension is quite straightforward: Include this package: import org.neo4j.logging.Log; In the method… Read more →

Viewing schema data with APOC Procedures

APOC Procedures offers meta procedures to view information about your database schema and the data it stores. The procedure apoc.meta.schema() uses a sampling of the graph data to produce a map of metadata on the graph labels, relationships, properties, and… Read more →

How to avoid using excessive memory on deletes involving dense nodes

In situations where you know you need to delete a bunch of nodes (and by rule their relationships as well), it can be tempting to simply use DETACH DELETE and be done with it. However, this can become problematic if… Read more →

Fast counts using the count store

Neo4j maintains a transactional count store for holding count metadata for a number of things. The count store is used to inform the query planner so it can make educated choices on how to plan the query. Obtaining counts from… Read more →

Neo4j’s commit process explained

This article will try to guide you through Neo4j’s commit and replication processes both for single instances and causal clusters.   Single Instance When you call tx.commit(), the transaction will go through the Storage Engine which will transform that transaction… Read more →

Understanding causal cluster size scaling

The ability to safely scale down the size of a causal cluster affords us more robustness for instance failures, provided we maintain quorum as the failures take place. Prior to 3.4, we used a single config property to define both… Read more →

How do I specify the field and array delimiter to neo4j-import as a ASCII character

neo4j-import allows one to initially load a graph.db via CSV files. There may be times when using a ‘,’ as a field or array delimiter is not appropriate as your data may contain this character as part of its data.… Read more →

Using apt to download a specific Neo4j debian package

By default, using apt-get to install Neo4j allows you to grab the current and previous stable releases. However, if you would like to install an older version, you can specify that. For reference, the Debian repo is located here:… Read more →