The latest M03 milestone release of Neo4j 2.0 is as you expected all about improvements to Cypher. This blog post also discusses some changes made in the last milestone (M02) which we didn’t fully cover.


MERGE
Cypher now contains a MERGE clause which is pretty big: It will be replacing CREATE UNIQUE as it also takes indexes and labels into accounts and can even be used for single node creation. MERGE either matches the graph and returns what is there (one or more results) or if it doesn’t find anything it creates the path given. So after the MERGE operation completes, Neo4j guarantees that the declared pattern is there.


We also added additional clauses to the MERGE statement which allow you to create or update properties as a function of whether the node was matched or created. Please note that — as patterns can contain multiple named nodes and relationships — you will have to specify the element for which you want to trigger an update operation upon creation or match.


MERGE (keanu:Person { name:’Keanu Reeves’ })
ON CREATE keanu SET keanu.created = timestamp()
ON MATCH  keanu SET keanu.lastSeen = timestamp()
RETURN keanu

We put MERGE out to mainly collect feedback on the syntax and usage, there are still some caveats, like not grabbing locks for unique creation so you might end up with duplicate nodes for now. That will all be fixed by the final release.


Going along with MERGE, MATCH now also supports single node patterns, both with and without labels.


Cypher Changes
Two new functions startNode(rel) and endNode(rel) allow quick access to both ends of a relationship.


Besides the existing USING index hints, you can now also require Cypher to scan the given labels for nodes (if it doesn’t do so automatically).


The Cypher ExecutionResult is now closeable and will immediately release resources upon closing. It’s no longer necessary to exhaust it.


We fixed an issue with UNION and textual output, close readonly index results and fixed an issue where index lookups failed with literal collections.


Transactional Cypher HTTP endpoint
Already with Milestone 2 we added a new Cypher HTTP endpoint for allowing transactions to span multiple HTTP requests. This endpoint only works with Cypher statements, of which you can post multiple in a single go. It streams data from and to the server and has a much more concise format for returning the data. Returned Nodes and relationships are just represented by their properties (a JSON map). Aside from improved support for transactionality, this API should perform better than the existing (older) Cypher REST Endpoint because of the decreased verbosity of the response.


You can use this endpoint to post a bunch of statements in one go, or post multiple read and write statements in sequence. Rollbacks are requested by HTTP DELETE requests and commits by POSTing to a commit URL.


Here is an example session:


Create Transaction and do some work.
>> POST http://localhost:7474/db/data/transaction
{ “statements” : [ {
   "statement" : "CREATE (n {props}) RETURN n",
   "parameters" : { "props" : { "name": "My Node" } }
} ] }


<< 201: Created
Location: http://localhost:7474/db/data/transaction/3
{
 “commit” : “http://localhost:7474/db/data/transaction/3/commit”,
 “results” : [ { “columns” : [ "n" ],
 “data” : [ [ { "name" : "My Node" } ] ] } ],
 “transaction” : { “expires” : “Tue, 28 May 2013 13:19:59 +0000″ },
 “errors” : [ ]
}


Commit transaction
>> POST http://localhost:7474/db/data/transaction/3/commit
{ “statements” : [ {
   "statement" : "MATCH n RETURN id(n)"
 } ] }


<< 200: OK
{
 “results” : [ { “columns” : [ "id(n)" ],
 “data” : [ [ 2 ] ] } ],
 “errors” : [ ]
}

The endpoint now supports transaction timeouts and keep-alive.


Periphery
In the Neo4j-Shell we added commands for listing automatic indexes and their state.
Also the BatchInserter is now label aware, allowing you to create initial Neo4j stores containing labels.


Breaking Changes
Please note that you cannot upgrade a graph database store from 2.0.0-M02 to 2.0.0-M03 due to incompatible changes in the store files. Please recreate your database for the newer version.

Milestone 2 contained some breaking changes:


  • Replaced protected fields from org.neo4j.graphdb.factory.GraphDatabaseFactory
  • Removed org.neo4j.graphdb.index.BatchInserterIndex and BatchInserterIndexProvider please use the ones in the package org.neo4j.unsafe.batchinsert
  • The BatchInserter and the BatchGraphDatabase are not binary compatible with 1.9 due to some methods now taking a varargs array of labels as last argument, please recompile your code
  • We removed the alternative WITH syntax (==== a,b,c ====)


As always we welcome you to try out the new milestone release and report back any feedback, issues or suggestions.


Latest documentation is here. You can also find Neo4j 2.0.0-M03 on maven central.


Thanks a lot to Michael Bach, Rich Simon, Robert Herschke, Wes Freeman, Aseem Kishore, Morteza Milani, Javier de la Rosa and many more for great feedback on Neo4j 2.0. Keep it coming.

 

Keywords:  


3 Comments

Transactional endpoint is just awesome :D

versae says:

Loving already the transactional endpoint.

Anonymous says:

Merge is awesome for nodes. But it doesn&#39;t work for relationships. Do you plan to implement it for relationships? Create unique doesn&#39;t handle our specific case, we need OnCreate and OnMerge ….

Leave a Reply

Your email address will not be published. Required fields are marked *

Stay Connected

Go
 

Have a Graph Question?

Stackoverflow
Contact Us


Popular Graph Topics

Archives