Batches and uniqueness

63 views
Skip to first unread message

Nigel Small

unread,
Oct 12, 2012, 6:30:09 AM10/12/12
to Neo4J
Hi chaps

I've hit a small feature in REST batch submissions which I can't find a way around. REST batches obviously allow references to items created within the same batch so that payloads like the following can create a pair of nodes with a relationship between them:

[
  { "id": 0, "method": "POST", "to": "/node",
    "body": {"name": "Alice"}
  },
  { "id": 1, "method": "POST", "to": "/node",
    "body": {"name": "Bob"}
  },
  { "id": 2, "method": "POST", "to": "{0}/relationships",
    "body": {"type": "KNOWS", "to": "{1}", "data": {"since" : "1999"}}
  }
]


This is fine until I want the nodes to be uniquely indexed. I then try this instead...

[
  { "id": 0, "method": "POST", "to": "/index/node/People?unique",
    "body": {"key": "name", "value": "Alice", "properties": {"name": "Alice"}}
  },
  { "id": 1, "method": "POST", "to": "/index/node/People?unique",
    "body": {"key": "name", "value": "Bob", "properties": {"name": "Bob"}}
  },
  { "id": 2, "method": "POST", "to": "{0}/relationships",
    "body": {"type": "KNOWS", "to": "{1}", "data": {"since" : "1999"}}
  }
]


...and receive a BatchOperationFailedException with an empty message. I have tested the node creation jobs (ids 0 and 1) from this on their own and they work fine. This indicates that the issue is with the relationship creation. I'm guessing that the substitutions {0} and {1} are substituting the "indexed" URI instead of the "self" URI for each of the nodes and so the URIs generated behind the scenes are invalid. Not sure though, something else may be going on...

Incidentally, I'm using curl for these tests to make sure the problem isn't client side. I've also run against the latest milestone and snapshot builds with similar results.

Help appreciated... I'm kinda stuck with this one :-/

Cheers
Nige

Peter Neubauer

unread,
Oct 18, 2012, 10:54:11 AM10/18/12
to ne...@googlegroups.com
Nigel,
yes, you are right. Just recreated that test, and you are getting back

http://localhost:7474/db/data/index/node/People/name/Alice/1

and

http://localhost:7474/db/data/index/node/People/name/Bob/2

So the question is how to handle this. Any suggestions? Should the
node URL be returned or the URI to the indexed entry?

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html
> --
>
>

kantube

unread,
Oct 18, 2012, 11:17:36 AM10/18/12
to ne...@googlegroups.com
peter,

shouldn't you always return the node uri?  what is the pros/cons of each?  don't all batch commands need to reference the node not the index?






Nigel Small

unread,
Oct 18, 2012, 11:44:54 AM10/18/12
to ne...@googlegroups.com
My instinct is that it should carry on returning the indexed URI as currently, not least because it would break existing code if changed, but also the "indexed" URI is the only way to perform an index entry removal. One way around it might be to allow the indexed URI to be used as an alias for the node URI (for certain operations only maybe?) This way you could have:

/index/node/People/name/Alice/1/relationships

as an alias for

/index/node/1/relationships

and that way all corresponding operations would be mapped.

WDYT? Not 100% sure about this one myself....
Nige


On 18 October 2012 16:17, kantube <mic...@mkanner.com> wrote:
peter,

shouldn't you always return the node uri?  what is the pros/cons of each?  don't all batch commands need to reference the node not the index?






--
 
 

kantube

unread,
Oct 18, 2012, 11:57:05 AM10/18/12
to ne...@googlegroups.com
nigel

good point. 

Peter Neubauer

unread,
Oct 19, 2012, 5:52:59 AM10/19/12
to ne...@googlegroups.com
Nigel,
I opened https://github.com/neo4j/community/issues/933 to discuss
this, and have an ignored test that we can fix coming in soon, if you
wanna work on this. Good?

Cheers,

/peter neubauer

G: neubauer.peter
S: peter.neubauer
P: +46 704 106975
L: http://www.linkedin.com/in/neubauer
T: @peterneubauer

Neo4j 1.8 GA - http://www.dzone.com/links/neo4j_18_release_fluent_graph_literacy.html


> --
>
>
Reply all
Reply to author
Forward
0 new messages