REST Unique Indexes

조회수 106회
읽지 않은 첫 메시지로 건너뛰기

kantube

읽지 않음,
2012. 3. 2. 오후 1:09:2012. 3. 2.
받는사람 ne...@googlegroups.com
I am looking into implementing the Unique Index REST interface.  if i understand this interface correctly a call to this /index/node/indexName?unique will create a node if and only if the key/value posted is not already in the index.  if it is in the index nothing is done (not even update of the properties).  so in order to update the properties another call needs to be made to update that node. 

is this a correct understanding of this? 
will there be additional interfaces for handling uniqueness in 1.7, such as insertOrUpdate?  

thanks

Peter Neubauer

읽지 않음,
2012. 3. 5. 오전 9:17:2312. 3. 5.
받는사람 ne...@googlegroups.com
Sounds like a good addition. Could you please raise an issue on this?
Also, if you feel comfortable, would you be willing to implement it an
do a Pull Request?

Cheers,

/peter neubauer

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

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

kantube

읽지 않음,
2012. 3. 5. 오전 10:29:4112. 3. 5.
받는사람 ne...@googlegroups.com
Peter,

in addition to InsertOrUpdate would it be possible to pass more then one Key/Value combo at one time?  for example if i have a user i would like to have both their email and userId unique (among other properties).  if my understanding is correct of this interface i can only pass one key/value and then have to make another call for the second item. 

I would really like to do this update but i am a .net guy and to get an environment up and running would take me more time than i have available at this moment.  however, will raise an issue on the InsertOrUpdate - that i have the time for :).

thanks
michael

Peter Neubauer

읽지 않음,
2012. 3. 6. 오전 4:20:4812. 3. 6.
받는사람 ne...@googlegroups.com
Mmh,
to me it is not entirely clear how to model several values in a good
way - couldn't these actually be in different indexes etc?

Cheers,

/peter neubauer

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

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

kantube

읽지 않음,
2012. 3. 9. 오전 9:59:3712. 3. 9.
받는사람 ne...@googlegroups.com
peter,

i think i stated this incorrectly. what i am trying to do is: if you have a table that has two (or more) columns with unique indexes on them you cannot insert a row that duplicates either column.  so to do this over REST i think the interface

http://localhost:7474/db/data/index/node/people?unique
{"key": "name", "value": "Tobias", "properties": {"name": "Tobias", "sequence": 1}}

could be changed to

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

and this would create a new node if and only if the key/value pairs where not found all of the indexes.  The above request InsertOrUpdate would be a little more complicated because you would have to verify that all found name/value pairs pointed to the same node before doing an update, but otherwise it should do insert/update. 

does that sound correct to you?





Max De Marzi Jr.

읽지 않음,
2012. 3. 9. 오후 12:15:4912. 3. 9.
받는사람 ne...@googlegroups.com
Couldn't you just combine the keys?

http://localhost:7474/db/data/index/node/people?unique
{"key""combined""value""Tobias-Tob...@mail.com""properties": {"name""Tobias", "email": "Tob...@mail.com", "sequence": 1}}

kantube

읽지 않음,
2012. 3. 9. 오후 1:24:0712. 3. 9.
받는사람 ne...@googlegroups.com
if you combining the keys how would the exact match on a key/value pair work? 


Max De Marzi Jr.

읽지 않음,
2012. 3. 9. 오후 1:55:5112. 3. 9.
받는사람 ne...@googlegroups.com
You put a dash between the keys in a predetermined order and you make that virtual attribute your key.

kantube

읽지 않음,
2012. 3. 12. 오전 9:38:3312. 3. 12.
받는사람 ne...@googlegroups.com
Max,

yes i understand on building a compound key, but i don't think it will work well with some use cases. for example, a user node where you want to have both the userId and email unique.

userId = jack email = ja...@mail.com
userId = jack email = ja...@mail.com

are two different compound keys and a new node would be created (not what is expected)

also if you have this compound key the sign in process would not have both key elements since most sign in forms only require a userId not both uid and email.  even searching to find a node becomes more problematic because all index elements may not be available at the time of searching,

i can think of several work around for this (simplest being using email for the uid but that is not what my client wants).  but think that having different indexes for each key is still the best.  and to ensure uniqueness over REST i think having the db do this is really the only solution. 

Also i have other use cases where i need to have uniqueness span across node types, for example i have several node types that have a url slug and that needs to be unique across groups of node types. 

unless i am not understanding something correctly i think the request for REST to support multiple indexes is a valid and very useful request, do you have another solution that would work?

Peter Neubauer

읽지 않음,
2012. 3. 12. 오전 10:17:1712. 3. 12.
받는사람 ne...@googlegroups.com
Mmh,
I think I understand what you are thinking. However, isn't the built
in logic in this a bit too heavy for a REST request? What happens if I
have a third index that is NOT unique as part of the properties?
Should that be baked into the same call or be a second normal indexing
call?

Cheers,

/peter neubauer

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

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

kantube

읽지 않음,
2012. 3. 12. 오전 11:21:1412. 3. 12.
받는사람 ne...@googlegroups.com
well i am thinking that the call

http://localhost:7474/db/data/index/node/unique {
"indexes": [ {"index":"indexName1", "key"
: "uid", "value": "Tobias"},
             {"index":"indexName2", "key": "email", "value": "Tob...@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": "Tob...@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


kantube

읽지 않음,
2012. 3. 14. 오전 10:52:0012. 3. 14.
받는사람 ne...@googlegroups.com
peter,

have you had any time to think more about this interface?  i would like to make a ticket for it so that maybe in a release far far in the future it will be added. 

actually this this is a bit of a workaround for me, i currently use a sql server tbl with a index to do this and i have several points of failure that i have to test for, not ideal, not even close to ideal. 
전체답장
작성자에게 답글
전달
새 메시지 0개