REST Mulitple Unique Indexes #145

Closed
lassewesth opened this Issue Nov 12, 2012 · 11 comments

Projects

None yet

3 participants

@lassewesth
Neo4j member

@SepiaGroup: 'Enhance the existing REST Unique API to support multiple indexes in one call: in reference to https://groups.google.com/forum/?fromgroups#!topic/neo4j/-YryBO8SkkI

http://localhost:7474/db/data/index/node/unique {
"indexes": [ {"index":"indexName1", "key": "uid", "value": "Tobias"},
{"index":"indexName2", "key": "email", "value": "Tobias@mail.com"}, ... ]
, "properties": {"name": "Tobias", "sequence"
: 1}}

would only be for unique indexes because wouldn't this call only be use for unique indexes regardless of how many index/key/value pairs were passed to it?

any other index updates would be called on another REST call as usual and not part of Unique transaction.

My thinking is that to ensure uniqueness you need to do the update to multiple indexes in one transaction and that is only possible (as far as i am aware of) over REST if the db does it.

Now thinking about the next step - updating: if you agree with the above then we would also need a way to update the index when required

http://localhost:7474/db/data/index/node/unique {
"indexes": [ {"index":"indexName1", "key": "uid", "value": "Tobias"},
{"index":"indexName2", "key": "email", "value": "Tobias@mail.com"}, ... ]
, "properties": {"name": "Tobias", "sequence"
: 1}
, "uri":"http://localhost:7474/db/data/node/116"}

would be the update call where uri points to the existing node, similar to

http://docs.neo4j.org/chunked/stable/rest-api-unique-indexes.html#rest-api-add-a-node-to-an-index-unless-a-node-already-exists-for-the-given-mapping

all index/key/value pairs would need to be checked against the key/values passed in the properties and if any duplicates are found the update fails for the entire call. Just like in sql if a key constraint is placed on a column in a table.

With this approach there is a very good chance that the index gets out of sync with the node properties (forget to add a index to the update call for example). maybe you can come up with some magic knowing the internals of the indexing better.

just my thoughts.
thanks'

@lassewesth
Neo4j member

values:

@lassewesth
Neo4j member

@jakewins: For executing multiple REST operations in one transaction, could you use the the Batch Operations API?

http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html

@lassewesth
Neo4j member

@SepiaGroup: Jacob,

yes that would work, had not thought of that. a little more work on my
side but it would work for what i am trying to do.

Thanks
Michael

On 4/2/2012 10:19 AM, Jacob Hansson wrote:

For executing multiple REST operations in one transaction, could you use the the Batch Operations API?

http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html


Reply to this email directly or view it on GitHub:
https://github.com/neo4j/community/issues/355#issuecomment-4879270

@lassewesth
Neo4j member

@nambrot: I'm just curious whether you have been able to solve the issue.

I am modeling users in my system and want to uniquely index on id and email, so it does seem like the batch API is the only way to go.

Nam

@lassewesth
Neo4j member

@SepiaGroup: Nam,

i am currently working on this update (been on vaca for the past few weeks). i have updated the Neo4jRestAPI to do batch updates and should be pushing the code when i am done testing. However, there is a small issue with Neo4j REST API with regard to this issue. Their API for "Unique" is "Create or Return" not "Create or Fail". Put it another way, if you pass a create new node/index request currently to Neo4j it will either crate the new node or return the existing node that matches the the index key/value. I have requested an additional Neo4J API call "CreateUnique" that would either create a new node if the key/value does not exist or return a http 302 (found) error. doing this will stop the transaction and function more closely to what a RDBMS would do. Peter at Neo4j requested that i make this change as well, so that will take a bit more time as i am a .net guy, but i am looking forward to do it.

Also i will be adding the new Cypher commands for mutating as soon as i am done with this update.

@lassewesth
Neo4j member

@nambrot: @SepiaGroup Appreciate it. My current solution looks really weird right now:

  • Create the node on the primary index (which is create or fail)
  • for each index
    • add the node to the index, check whether its the the first node on retrieval through the index
  • if that was successful, we have completed the transaction, if not, we have to remove the node from the indicies and the primary index as well + delete the node itself.

Bottom line:
Please implement it natively in the REST API :)

@lassewesth
Neo4j member

@SepiaGroup: Nam,

i am a bit confused on what you are asking. i just pushed an update that will do batch commands (look at the BatchStoreTest.cs file on how to do this. i just have not had time to update the docs but will do so this weekend). now this update has some breaking changes to support the batch data store class. the other breaking change is that i removed NodeType from CreateNode/CreateRelationship. i did this because Neo4j does not use NodeType natively and it is something that i use but others may not. to get around this just store NodeType in a property (this is what the API did anyway).

please let me know how this works for you. i will be updating the API very shortly to support Cypher mutating commands (i really need this for my project). if there is anything else missing or any use case that you are having issues with let me know and i can see if i can help.

Peter: i answered the SO question - thanks for pointing it out.

@lassewesth
Neo4j member

@nambrot: Sorry if I wasnt clear. I try to use mutliple indicies in a traditional way as I want the values to be unique as in your original post. Right now, you can only create a node on one index uniquely only. meaning that if you add an already created node to an index, you are not guaranteed to be unique on later indicies.

Was that clear?

@jakewins

@nambrot was this resolved? If I understand your use-case, you want to insert into multiple unique indexes within one transaction, correct?

If so, you should be able to use the REST Batch API, see here: http://docs.neo4j.org/chunked/stable/rest-api-batch-ops.html

Closing this. Please re-open if I misunderstood.

@jakewins jakewins closed this Feb 18, 2013
@nambrot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment