Neo4j Query Language - Cypher vs Gremlin

I'm starting to develop with Neo4j using the REST API. I saw that there are two options for executing complex queries: Cypher (Neo4j query language) and Gremlin (general purpose query / crawl language).

Here, what I want to know is there any request or operation that can be done with Gremlin and cannot be performed with Cypher? or vice versa?

Cypher seems to me more understandable than Gremlin, and in general it seems that the guys from Neo4j go with Cypher. But - if Cypher is limited in comparison with Gremlin - I would really like to know this in advance.

+82
neo4j graph-databases cypher gremlin
Dec 11
source share
8 answers

For general queries, Cypher is sufficient and probably faster. Gremlin's advantage over Cypher is that you go on a high level of crawl. In Gremlin, you can better define the exact workaround pattern (or your own algorithms), while in Cypher the engine tries to find the best workaround solution.

I personally use Cypher because of its simplicity, and to date I have not had situations in which I had to use Gremlin (except for working with graphl import / export functions from Gremlin). I expect, however, that even if I needed to use Gremlin, I would do it for a specific query that I would find on the network and never return again.

You can always learn Cypher very quickly (in days), and then continue (longer) overall Gremlin.

+59
Dec 12
source share

We have to go through thousands of nodes in our requests. Cypher was slow. The Neo4j team informed us that the implementation of our algorithm directly against the Java API will be 100-200 times faster. We did this and got an easy factor of 60 out of it. At the moment, we do not have a single Cypher request in our system due to mistrust. Easy Cypher requests are easily written in Java, complex requests will not be executed. The problem is that when you have several conditions in the request, there is no way in Cypher to indicate in which order to perform crawls. Thus, your cypher request may go crazy on a graph in the wrong direction. I did not do much with Gremlin, but I could imagine that you get much more control over the execution with Gremlin.

+31
Mar 22 '13 at 14:43
source share

The collective efforts of Neo4j at Cypher were really impressive, and it has come a long way. The Neo team usually pushes people towards it, and as Cypher ripens, Gremlin will probably pay less attention. Cypher is a good long-term choice.

However, Gremlin is a Groovy DSL. Using it through your Neo4j REST endpoint provides complete, unhindered access to the Neo4j core API. It (and other script plugins in the same category) cannot be matched in terms of low level power. Alternatively, you can run Cypher from the Gremlin plugin .

In any case, there is a reasonable upgrade path where you will find out to both. I will go with the one who lifts you and runs faster. In my projects, I usually use Gremlin and then call Cypher (from Gremlin or not) when I need tabular results or expressive pattern matching - both are a pain in Gremlin DSL.

+25
Jan 04 '13 at 16:20
source share

At first I started using Gremlin. However, at that time, the REST interface was a bit unstable, so I switched to Cypher. It has much better support for Neo4j. However, there are several types of queries that are simply not possible with Cypher, or where Cypher cannot fully optimize the way Gremlin is used.

Gremlin is built on top of Groovy, so you can use it as a general way to get Neo4j to execute Java code and perform various tasks from the server, without having to use an HTTP hit from the REST interface. Among other things, Gremlin will allow you to change data.

However, when all I want is to request data, I go with Cypher as it is more readable and easier to maintain. Gremlin is reserved when the limit is reached.

+17
Dec 11
source share

Gremlin requests can be generated programmatically. (See http://docs.sqlalchemy.org/en/rel_0_7/core/tutorial.html#intro-to-generative-selects to understand what I mean.) This seems a bit more complicated with Cypher.

+7
Apr 11 '13 at 7:39
source share

Cypher is a declarative query language for querying graph databases. The term declarative is important because it is a different way of programming than programming paradigms such as imperative. In a declarative query language, such as Cypher and SQL, we tell the underlying engine what data we want to receive, and do not indicate how we want the data to be selected. In Cypher, the user defines the subgraph of interest in the MATCH clause. Then, the base engine starts the pattern matching algorithm to search for similar occurrences of the subgraph in the graph database. Gremlin has both declarative and imperative features. This is a graph traversal language in which the user must give clear instructions on how to navigate the graph. The difference between these languages ​​in this case is that in Cypher we can use the Kleene star operator to find the paths between any two given nodes in the graph database. However, at Gremlin we will have to explicitly define all such paths. But we can use the retry operator in Gremlin to find many occurrences of such explicit paths in the graph database. However, iterating over explicit structures in Cypher is not possible.

+2
Feb 20 '19 at 7:34
source share

The long answer is short: use cypher for request and gremlin for workaround. You yourself will see the response time.

+1
Mar 20 '18 at 18:36
source share

Cypher only works for simple queries. When you start incorporating complex business logic bypassing graphs, it becomes too slow or stops working at all.

Gremlin is harder to learn, but it is also more powerful. You can implement any logic you can think of in Gremlin.

I would really like Neo4J to come with a Gremlin switch server. You can run Gremlin against a live instance of Neo4J, but for this you need to jump through many hoops. I hope that since Neo4J competitors allow Gremlin as an option, Neo4J will follow suit.

0
Apr 10 '19 at 0:03
source share



All Articles