GraphAware Blog - Cypher

Find out what's new in the Neo4j world

Avoid cycles in Cypher queries

26 Apr 2019 by Jan Zak Neo4j Beginner Cypher

Avoid cycles in Cypher queries

There is one common performance issue our clients run into when trying their first Cypher queries on a dataset in Neo4j. When writing a query, be sure that it doesn’t match any cycles, or you can experience unpleasant surprises. Assume the following sample graph and simple query: CREATE (a:Node {name: "A"}), (b:Node {name: "B"}), (c:Node {name: "C"}), (a)-[:TO {name: "1"}]->(b), (a)-[:TO {name: "2"}]->(b), (a)-[:TO {name: "3"}]->(b), (b)-[:TO {name: "4"}]->(c) MATCH p=({name: "A"})-[*..10]-({name: "C"}) RETURN p The query returns 9 paths, instead of 3 as you might have guessed! The additional 6 paths have length 4 with node pattern A-B-A-B-C, note...

Deep Dive into Neo4j 3.5 Full Text Search

11 Jan 2019 by Christophe Willemsen Neo4j Cypher Search

Deep Dive into Neo4j 3.5 Full Text Search

In this blog we will go over the Full Text Search capabilities available in the latest major release of Neo4j. Contrary to our usual blogs, the content will rather focus on the underlying search engine used by Neo4j, that is Apache Lucene in version 5.5.5 . What exactly is Search ? Search is an interaction between a user and a search engine. The user has an information need at hand and attempts to satisfy it by providing a search with adequate constraints. The search engine uses those constraints to collect matching results and return them to the user. What is...

Reverse Engineering Book Stories with Neo4j and GraphAware NLP

24 Jul 2017 by Christophe Willemsen Neo4j NLP Cypher

A book tells us a story, but for a computer it is a wall of text. How can we use graphs and NLP to help our machines make more sense of a story? Our example comes from the A Song of Ice and Fire books, aka Game of Thrones. We converted the e-books (epub) to text-files and used a small python program to split them into chapters, paragraphs, and sentences. So a book turned into this model : GraphAware NLP GraphAware NLP Framework is a project that integrates NLP processing capabilities available in several software packages like Stanford NLP and...

Graph-Aided Search - The Rise of Personalised Content

20 Apr 2016 by Alessandro Negro, Christophe Willemsen Neo4j Cypher Recommendations Elasticsearch

In our previous blog post we introduced the concept of Graph Aided Search. It refers to a personalised user experience during search where the results are customised for each user based on information gathered about them (likes, friends, clicks, buying history, etc.). This information is stored in a graph database and processed using machine learning and/or graph analysis algorithms. A simple example is the LinkedIn search functionality. If we were typing “Michal” in the text input, it would obviously return people where the name matches and order them by full text relevancy with some fuzziness: Lucene-based search engines such as...

Processing Large Sets of Nodes with Cypher

10 Dec 2015 by Christophe Willemsen Neo4j Cypher

Iterating over large numbers of nodes using Cypher is quite a common use case in Neo4j. Typically, the reason for doing this is that we want to perform some kind of operation for each one of these nodes. In this blog post, we will use one million TestNodes and try to iterate over them in order to index their contents into a freshly created Elasticsearch index. There are three approaches we can take, two of which are quite common, but the most performant technique is largely unknown. First Technique : SKIP and LIMIT Using SKIP and LIMIT is the first...

Faster Recommendations with Neo4j 2.3 Triadic Selection

20 Oct 2015 by Alessandro Negro, Christophe Willemsen Neo4j Cypher Recommendations

Recently, Neo Technology announced the 2.3.0-RC1 release of their Neo4j graph database. One of the key new features is Triadic Selection built into Cypher’s Cost Based Planner. In this blog post, we will explore the Triadic Selection in detail and demonstrate how significantly it can speed up recommendations computed in Neo4j. What is Triadic Selection? A Bit of Theory: Triadic Closure Networks or graphs can rarely be considered static structures. On the contrary, often they seem to be ever-evolving objects. Any social network, for example, is often the most dynamic of graphs: at any moment, new relationships are created between...

Cypher: Variable Length Relationships by Example

19 May 2015 by Christophe Willemsen, Michal Bachman Neo4j Cypher

In this blog post, we’ll demonstrate how to use variable length relationships (sometimes called “variable length paths”) in Cypher using examples. We will also see when zero length relationships can be useful. Introduction Let’s start with the basics. For the sake of the blog post, our use case will be users that know other users. Users write blog posts modeled as linked lists: You can generate an example graph with the following link to a predefined Graphgen graph, or use this Neo4j Console if you want to execute the queries whilst reading the blog post. Basic Relationships Matching Let’s start...

MATCHing Paths with Very Dense Nodes in Neo4j 2.2

19 Mar 2015 by Christophe Willemsen Neo4j Cypher Intermediate

Last weekend, I came across a tweet announcing that Wikimedia released the dataset of the page clickstreams for February 2015. I found it interesting to download this dataset and see how people arrive on the Neo4j’s Wikipedia page. The data is quite simple; we have page entities that relate to other pages. A page can either be a Wikipedia page, or a non-Wikipedia page such as Google. Relationships can represent a user click from a Wikipedia page to another page, or a user searching on Google or Wikipedia. The number of times an event occurs is also provided in the...

Modelling Data in Neo4j: Labels vs. Indexed Properties

16 Jan 2015 by Christophe Willemsen Neo4j Modelling Cypher Intermediate

A common question when planning and designing your Neo4j Graph Database is how to handle “flagged” entities. This could include users that are active, blog posts that are published, news articles that have been read, etc. Introduction In the SQL world, you would typically create a a boolean|tinyint column; in Neo4j, the same can be achieved in the following two ways: A flagged indexed property A dedicated label Having faced this design dilemma a number of times, we would like to share our experience with the two presented possibilities and some Cypher query optimizations that will help you take a...

Cypher MERGE Explained

31 Jul 2014 by Luanne Misquitta Neo4j Beginner Cypher

With MERGE set to replace CREATE UNIQUE at some time, the behavior of MERGE can sometimes be tricky to understand. MERGE Here’s a summary of what MERGE does: It ensures that a pattern exists in the graph by creating it if it does not exist already It will not use partially existing patterns- it will attempt to match the entire pattern and create the entire pattern if missing When unique constraints are defined, MERGE expects to find at most one node that matches the pattern It also allows you to define what should happen based on whether data was created...