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 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 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:  


Comparing relationship properties within a path

You want to compare relationship-properties of a path, either by a global value or parameter, or with each other within a path. Basic model: (:Person {person_id:’123′})-[:FRIEND {date:’1972-01-01′}]->(m:Person {person_id:’456′}) Make sure to have an constraint OR index on your nodes: Constraint… Read more →

Explore:  


Limiting MATCH results per row

Since LIMIT applies to the total number of rows of the query, it can’t be used in cases when matching from multiple nodes where the limit must be on match results per row. Take an example case using the Movies… Read more →

Explore:  


Understanding non-existent properties and working with nulls

In Neo4j, since there is no table schema or equivalent to restrict possible properties, non-existence and null are equivalent for node and relationship properties. That is, there really is no such thing as a property with a null value; null… 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:  


Understanding aggregations on zero rows

Aggregations in Cypher can be tricky in some cases. Notably, when performing aggregation right after a MATCH where there are no matches, or after a filter operation that filters out all results. In some cases a query using aggregations in… 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:  


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:  


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:  


How do I define, display, and use parameters with neo4j-shell

bin/neo4j-shell allows for a command line interface to query your graph via Cypher statements and to include parameters to those statements. Usage of parameters, rather than hard coding values, will allow for re-use of the query plan cache. A parameter… Read more →

Explore:  


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 →

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 define a LOAD CSV FIELDTERMINATOR in hexidecimal notation

When using LOAD CSV one can define the field delimiter used, whereby the default is the ‘,’ character. If you want to override the default this can be accomplished via the paramter FIELDTERMINATOR, for example LOAD CSV WITH HEADERS from… 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 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:  


All shortest paths between a set of nodes

Consider a number of arbitrary nodes, A,B,C,D,E,F,…​.. I wish to return all of the shortest paths between these nodes. The nodes may have many edges between them, but anticipate a maximum of 4. The graph is complex and non hierarchical… Read more →

Explore:  


Performing match intersection

Match intersection is a common use case where you’re searching for nodes which have relationships to all of a set of input nodes. For the rest of the article we’ll use the built-in movies graph for demonstration. The example use… 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 to get a high level inventory of objects in your graph (part 2)

Following the knowledge base article on How to get a high level inventory of objects in your graph, this article will cover how to get more detailed high level inventory of objects in your graph. The first article showed how… Read more →

Explore:  


How do I display the nodes with the most properties

To display the nodes with the most properties defined, run the following Cypher: MATCH (n) RETURN labels(n), keys(n), size(keys(n)), count(*) ORDER BY size(keys(n)) DESC Representative output is similar to: labels(n) keys(n) size(keys(n)) count(*) [Movie] [TotalRevenue, year_of_release, name, id] 4 1… Read more →

Explore:  


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 →

Explore:  


Performing pattern negation to multiple nodes

Some use cases require matching to nodes which aren’t connected to any of some other set of nodes. We’ll discuss both incorrect and correct approaches to this kind of query. For our examples we’ll use a recipe graph, where the… Read more →

Explore: