How do I report on nodes with multiple labels

If your data model has choosen to define multiple labels on a node, for example create (n:Actor:Director {name:’Clint Eastwood’}) To find all nodes which are defined with both labels of Actor AND Director use the following Cypher: match (n) where… Read more →

Explore:  


Understanding how MERGE works

What is MERGE, and how does it work? The MERGE clause ensures that a pattern exists in the graph. Either the pattern already exists, or it needs to be created. In this way, it’s helpful to think of MERGE as… Read more →

Explore:  


Post-UNION processing

Cypher does not allow further processing of UNION or UNION ALL results, since RETURN is required in all queries of the union. Here are some workarounds. Post-UNION processing in Neo4j 4.0 With Neo4j 4.0, post-UNION processing is now possible via… Read more →

Explore:  


How do I pass parameters when calling apoc.cypher.runFile

APOC allows one to have a stored procedure, apoc.cypher.runFile, to then run the contents of the file to the Cypher engine. To allow the reading of the file in the conf/neo4j.conf one needs to define apoc.import.file.enabled=true and then if one… Read more →

Explore:  


Explantion of debug.log message of Commits found after last checkpoint

When running backup for example bin/neo4j-admin backup –backup-dir=/home/neo4j/backups/01172020/ –name=graph.db you may observe in the output of said command detail similar to 2020-01-17 12:54:06.767+0000 INFO [o.n.b.i.BackupOutputMonitor] Finish receiving store file /home/neo4j/backups/backups/01172020/graph.db/temp-copy/schema/index/lucene_native-2.0/5/native-1.0/profiles/index-5.708254.cacheprof 2020-01-17 12:54:06.767+0000 INFO [o.n.b.i.BackupOutputMonitor] Start receiving store file /home/neo4j/backups/backups/01172020/graph.db/temp-copy/schema/index/lucene_native-2.0/5/string-1.0/profiles/index-5.708254.cacheprof 2020-01-17… Read more →

Explore:  


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 →

Explore:  


Explanation of error “Cannot merge node using null property value for”

When running a MERGE, which is a combination of MATCH and/or CREATE one may encounter an error of Cannot merge node using null property value for if the MERGE is performing a MATCH against a null property. For example, when… Read more →

Explore:  


How do I compare two graphs for equality

If you are looking to compare 2 graphs (or sub-graphs) to determine if they are equivalent, the following Cypher will produce a md5sum of the nodes and properties to make that comparison. For example, you may wish to compare a… Read more →

Explore:  


Neo4j: Convert string to date

Neo4j 3.4 saw the introduction of the temporal date type, and while there is now powerful in built functionality, converting strings to dates is still a challenge. If our string is in the format yyyy-MM-dd we can call the date… Read more →

Explore:  


How do I produce a profile/explain through cypher-shell and pipeing query file

If yor prepare a file with a Cypher statement that includes either a profile or explain clause and then want to pipe that file to bin/cypher-shell, to produce the profile/explain output you must include –format verbose on the command line.… Read more →

Explore:  


How to write a Cypher query to return the top N results per category

The following Cypher describes how you can display the Top 5 test scores within an entire :Score population broken out by a field_of_study property. create (n:Score {student_id: ‘DC001’, score: 89, field_of_study: ‘chemistry’}); create (n:Score {student_id: ‘MK812’, score: 97, field_of_study: ‘chemistry’});… Read more →

Explore:  


Understanding the Query Plan Cache

When a Cypher statement is first submitted Neo4j will attempt to determine if the query is in the plan cache before planning it. By default Neo4j will keep 1000 query plans in cache based upon the conf/neo4j.conf parameter of dbms.query_cache_size.… Read more →

Explore:  


Why doesn’t my WHERE clause work?

It can be frustrating when it seems like a WHERE clause isn’t working. You can use these approaches to figure out what’s wrong. Check for WHERE clauses following OPTIONAL MATCH WHERE clauses can’t be used on their own, they are… Read more →

Explore:  


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 →

Explore:  


How do I view the column headers of a CSV file with LOAD CSV

If one has a CSV file with the following content id,name,dob,addr1,addr2,city,state,country 1,Joe Smith,04/23/1971,121 Main Street,San Mateo,CA,USA 2,Bill Williams,09/21/2008,43 Overlook St,San Mateo,CA, USA and one simply wants to run a LOAD CSV command to have the column headers returned, the following… Read more →

Explore:  


How to avoid costly traversals with join hints

When matching a pattern using Cypher, the number of possible paths to evaluate often correlates with query execution time. When there is a supernode in the path (a node with a high number of relationships whose type are included in… Read more →

Explore:  


How do I perform the equivalent of a SQL Create Table as Select with Cypher

With a traditional SQL RDBMS one could perform a create table as select (i.e. CTAS) whereby its purpose is to create a new table and copy existing data from the original table to the new copy. If you are looking… Read more →

Explore:  


Understanding Neo4j Query Plan Caching

This article is based on the behavior of Neo4j 2.3.2. Query plan caching is governed by three parameters, as defined in the conf/neo4j.properties file, which are detailed here. The three parameters which govern whether a Cypher statement is planned/replanned are:… Read more →

Explore:  


How do I improve the performance of counting number of relationships on a node

Using Cypher one could count number of relationships in the following manner MATCH (n:Actor {name:’Sylvester Stallone’})–>() RETURN count(*); Which will report the number of incoming/outgoing relationships for the Actor named Sylvester Stallone. Using bin/neo4j-shell and running a profile on the… Read more →

Explore:  


Fulltext search in Neo4j

Note Please note that in Neo4j 3.5 fulltext search is available in Neo4j as part of Cypher stored procedures. More documentation is found here: https://neo4j.com/docs/cypher-manual/3.5/schema/index/#schema-index-fulltext-search. Fulltext search in Neo4j is supported by means of fulltext schema indexes. Fulltext schema indexes… Read more →

Explore:  


How to check for time range overlap in Cypher

Neo4j 3.4 introduced temporal types into Cypher, so now we have dates, dateTimes, and their local versions, too, as well as durations. While we don’t have a type for time ranges, we can use two temporal instants as the start… Read more →

Explore:  


Working with streaks in Cypher

When using Cypher for data analysis, you might have a problem where you need to identify or filter based upon some kind of streak. For example, for a sports graph, you might want to know the maximum number of consecutive… Read more →

Explore:  


Explanation of error LOAD CSV error of “Couldn’t load the external resource …​”

When running a LOAD CSV Cypher statement, for example LOAD CSV WITH HEADERS FROM “http://10.12.1.2/Neo4j/cities.csv” AS row WITH row create (c:cities {name:row.city}); whether through bin/neo4j-shell or the browser at http://localhost:7474 this may result in an error as follows Couldn’t load… Read more →

Explore:  


Using Cypher to generate Cypher statements to recreate indexes and constraints

The following can be used to extract index definitions and constraint definitions from an existing database and the resultant output can be played back on another Neo4j database. For example with the :play movies dataset as when run from the… Read more →

Explore:  


How do I display all nodes with no defined labels

Although assigning a node one or more labels provides many benefits (i.e. performance gains from index usage, ability to group nodes into sets, etc), it is possible to create a node without any labels. The following Cypher can be used to… Read more →

Explore: