Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j - Cypher vs Gremlin query language

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

Here's what I want to know - is there any query or operation that can be done by using Gremlin and can't be done with Cypher? or vice versa?

Cypher seems much more clear to me than Gremlin, and in general it seems that the guys in Neo4j are going with Cypher. But - if Cypher is limited compared to Gremlin - I would really like to know that in advance.

like image 371
Rubinsh Avatar asked Dec 11 '12 17:12

Rubinsh


People also ask

Does Neo4j use Gremlin?

Ted: Well you can go native with Neo4j, it has the Cypher language which is declarative, and Neo4j also supports Gremlin. Using Gremlin helps you to avoid vendor lock-in.

Which query language is used in Neo4j?

Contents. Cypher is Neo4j's graph query language that lets you retrieve data from the graph.

Is Neo4j better than SQL?

Neo4j ist not generally faster than an SQL database. It is just in many cases faster for graph based problems. For example if you'd like to find the shortest path between two entities Neo4j will most likely outperform MySQL etc.

What are the weaknesses of Neo4j?

Neo4j has some upper bound limit for the graph size and can support tens of billions of nodes, properties, and relationships in a single graph. No security is provided at the data level and there is no data encryption. Security auditing is not available in Neo4j.


2 Answers

For general querying, Cypher is enough and is probably faster. The advantage of Gremlin over Cypher is when you get into high level traversing. In Gremlin, you can better define the exact traversal pattern (or your own algorithms) whereas in Cypher the engine tries to find the best traversing solution itself.

I personally use Cypher because of its simplicity and, to date, I have not had any situations where I had to use Gremlin (except working with Gremlin graphML import/export functions). I expect, however, that even if i would need to use Gremlin, I would do so for a specific query I would find on the net and never come back to again.

You can always learn Cypher really fast (in days) and then continue with the (longer-run) general Gremlin.

like image 94
ulkas Avatar answered Sep 18 '22 14:09

ulkas


We have to traverse thousands of nodes in our queries. Cypher was slow. Neo4j team told us that implementing our algorithm directly against the Java API would be 100-200 times faster. We did so and got easily factor 60 out of it. As of now we have no single Cypher query in our system due to lack of confidence. Easy Cypher queries are easy to write in Java, complex queries won't perform. The problem is when you have multiple conditions in your query there is no way in Cypher to tell in which order to perform the traversals. So your cypher query may go wild into the graph in a wrong direction first. I have not done much with Gremlin, but I could imagine you get much more execution control with Gremlin.

like image 28
Heinrich Avatar answered Sep 20 '22 14:09

Heinrich