Neo4j and gremlin plugin install guide

29/08/2011: OBSOLETE – Now baked into the Core of Neo4j.

Hi,

I was having some difficulties getting the Gremlin query plugin working correctly with the Neo4j server which we will host on a Windows Azure VM.

Below is some steps to get this working nicely.

Firstly you will of course need to have Neo4j running. Then all we need to do is install the following:

Java JDK – Here is my version
java version “1.6.0_26”
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

JDK is needed to compile the plugin.

Maven 2.2.1 (There is compilation errors with SnapShot compiles with 3.0.3 at time of writing)
http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-2.2.1-bin.zip

Also, we need MVN, this is used to compile the Gremln Plugin. I was have problems with

Neo4j gremlin plugin
https://github.com/neo4j/gremlin-plugin

I like to setup environment variables to Neo4j server folder, java_home and also the maven location.

image

Once done we can then compile the plugin and copy it into the Neo4j plugins folder.

mvn clean package 
copy target\neo4j-gremlin-plugin-0.1-SNAPSHOT.jar $NEO4J_HOME\plugins 
cd $NEO4J_HOME\bin\neo4j.bat restart

Compiled version of the plugin.

image

Here we can see the plugin in the folder.

image

Now, to ensure Neo4j has the plugin, we can execute a curl command to check the extension is installed:

C:\Users\Romiko>curl localhost:7474/db/data/
{
  "relationship_index" : "http://localhost:7474/db/data/index/relationship",
  "node" : "http://localhost:7474/db/data/node",
  "relationship_types" : "http://localhost:7474/db/data/relationship/types",
  "extensions_info" : "http://localhost:7474/db/data/ext",
  "node_index" : "http://localhost:7474/db/data/index/node",
  "reference_node" : "http://localhost:7474/db/data/node/0",
  "extensions" : {
    "GremlinPlugin" : {
      "execute_script" : "http://localhost:7474/db/data/ext/GremlinPlugin/graphd
b/execute_script"
    }
  }
}

As we can see above, the rest result from the server has the GremlinPlugin Extension. In fact we can now do an HTTP Post Gremlin query to get the nodes from the object graph in the database.

e.g.

I want to see if I have a Node at the second level that has a relationship of type Related To with the Out Direction.

g.v(1).outE(‘RELATED_TO’)

Now we need to URL encode this.

+g.v(1).outE(%27RELATED_TO%27)

curl -d “script=+g.v(1).outE(%27RELATED_TO%27)” http://localhost:7474/db/data/ext/GremlinPlugin/graphdb/execute_script

as we can see the output is:

C:\Users\Romiko>curl -d “script=+g.v(1).outE(%27RELATED_TO%27)” http://localhost

:7474/db/data/ext/GremlinPlugin/graphdb/execute_script

[ {

“start” : “http://localhost:7474/db/data/node/1″,

“data” : {

},

“self” : “http://localhost:7474/db/data/relationship/23″,

“property” : “http://localhost:7474/db/data/relationship/23/properties/{key}”,

“properties” : “http://localhost:7474/db/data/relationship/23/properties”,

“type” : “RELATED_TO”,

“extensions” : {

},

“end” : “http://localhost:7474/db/data/node/2″

} ]

We have Node 23 being related to Node 2. (Remember Node 0, then Node 1).

the above result can be confirmed in the gremlin console (now baked into Neo4j) as of June 2011.

Note: The gremlin extension that is now part of theneo4j server\lib extensions is not for rest API queries, you still need this plugin!

  • gremlin> g.v(1).outE(‘RELATED_TO’)
  • ==> e[23][1-RELATED_TO->2]
  • gremlin>

Here is a screenshot of the gremlin console now baked into Neo4j.

image

image

Hope this gets you started with Neo4j and the gremlin plugin query language Smile

I might be looking at building a custom IQuerable expression translation, so we can then use Linq to query a gremlin based API. Might be fun to do, but first need to learn more about gremlin and Neo4j.

There is a fluent API for gremlin queries you can leverage as a .Net client:

NuGetPackage:
Source Code at:

Cheers

Advertisement

6 thoughts on “Neo4j and gremlin plugin install guide

  1. copy target/gremlin-translator-plugin-0.1-SNAPSHOT.jar $NEO4J_HOME/plugins

    should be

    copy target/gremlin-plugin-0.1-SNAPSHOT.jar $NEO4J_HOME/plugins

    Pierre

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s