Neo4j 1.6: support unique index "put if absent" #14

Closed
aseemk opened this Issue Jan 29, 2012 · 15 comments

Projects

None yet

6 participants

@aseemk
Member
aseemk commented Jan 29, 2012

1.6 adds this:

o Exposes get-or-create-uniquely via REST in ex. POST /index/node/?unique {...}

We should consider adding support for specifying this in our library too. Low-pri for us because we prefer to use the auto-index, so we never manually index stuff currently.

@drd0rk
drd0rk commented Feb 9, 2012

Hi,

I would be pleased by this feature being available.

greets

@mypark
mypark commented Aug 30, 2012

+1 for me to, would be simple to add I would think..

@freeeve
freeeve commented Oct 4, 2012

I think this is pretty easily handled in Cypher nowadays (1.8+), but I could be wrong about the specifics.

@aseemk
Member
aseemk commented Oct 4, 2012

Cypher supports that notion relative to a relationship (create this node connected to foo if no other node is connected to foo), while unique indexing is relative to a property (create this node with foo:bar if no other node has foo:bar). It's an interesting difference.

@freeeve
freeeve commented Oct 4, 2012

Yeah, I played around with it for a bit (even using just plain CREATE instead of CREATE UNIQUE), but I think you're right. Might warrant adding some sort of similar functionality to Cypher in 1.9--seems like a good use case.

@aseemk
Member
aseemk commented Oct 11, 2012

Some great discussion on this subject with @flipside in issue #36:

#36 (comment) (GitHub shows this URL as just going to the issue, but it'll go to the specific comment that starts this discussion)

Thoughts/feedback welcome, in particular your use case -- is it more for creating nodes uniquely or indexing them uniquely?

@alexeichemenda

Hey guys,
Just wanted to get an update on whether this feature (creating new node only if a node with same properties does not exist) is going to be implemented ? (Or if it is already implemented by now ?)

And I mean not looking at any relationships. Basically what I would love is doing :
START user=node(1)
CREATE UNIQUE user-[:friend]-(otherUser {name:"Alexei", type:"user"})
and it would only create a node (otherUser {name:"Alexei", type:"user"}) if it doesn't exist yet, regardless of any relationships.

How could I do that ?

Thanks !

@aseemk
Member
aseemk commented May 2, 2013

Hey @alexeichemenda, sorry this hasn't been implemented yet! There's a pull request open that I've been meaning to finish up (it could use some tests and a bit of cleaning up). I'd love to get to that soon.

@alexeichemenda

Thanks for the reply @aseemk. Is there any way I can help make this process faster ? I would love to see this feature implemented really quickly (within the next 10 days ?). If we both work on this issue, when do you think it would be possible to make it available ?

And do you see any bypass for a temporary solution ? I am interacting with neo4j through javascript, sending cypher queries through REST api. Thanks ;)

@aseemk
Member
aseemk commented May 6, 2013

Oh man, sorry for the delay @alexeichemenda. Your help would be great. The pull request is #55. You could pull that branch locally, rebase to the latest develop here, and run that locally and make sure it works for you. (And run the tests too and make sure they work for you?)

If it works for you and you have no issues, I can prioritize merging it in and pushing a new release out later this week! That also means then that in the meantime, you can push that branch to your own fork of this project, and update your npm to point to your fork until this release is live. That way you don't have to wait for me either. =)

Let me know, and thanks for your offer to help!

@alexeichemenda

Great !
I won't have much time until Saturday, but I'll definitely do that before next Wednesday.

I'll mail you if I have any problems.
Take care !

Sent from Mailbox for iPhone

On Mon, May 6, 2013 at 9:28 PM, Aseem Kishore notifications@github.com
wrote:

Oh man, sorry for the delay @alexeichemenda. Your help would be great. The pull request is #55. You could pull that branch locally, rebase to the latest develop here, and run that locally and make sure it works for you. (And run the tests too and make sure they work for you?)
If it works for you and you have no issues, I can prioritize merging it in and pushing a new release out later this week! That also means then that in the meantime, you can push that branch to your own fork of this project, and update your npm to point to your fork until this release is live. That way you don't have to wait for me either. =)

Let me know, and thanks for your offer to help!

Reply to this email directly or view it on GitHub:
#14 (comment)

@aleksandrenko

I kinnda' fix it, for me.
You have to use neo4j 1.9, and small correction you have to do is in index methods for node and relationship. Here is my change for the node index method:

from line 204:
else {
var urlToPost = ((("" + services.node_index) + "/") + index + '?uniqueness=create_or_fail');
/* 123 _/ return __this.request.post({
/
124 */ url: urlToPost,

/* 125 / json: {
/
126 / key: key,
/
127 / value: value,
/
128 / uri: __this.self
}
}, __cb(
, __frame, 17, 21, function ___(__0, _4) {
/
123 */ response = __4;
__then();
}, true));

@alexeichemenda

That's great! I'll definitely give it a try tomorrow. Sorry I have been very
busy lately and didn't have a chance to do it myself.

I'll keep you posted ASAP.

From: Nikolai notifications@github.com
Reply-To: thingdom/node-neo4j
<reply+i-3012883-eb344cd3c4493a057236ec19baef1b3898b067b3-1675106@reply.gith
ub.com>
Date: Thu, 30 May 2013 08:56:14 -0700
To: thingdom/node-neo4j node-neo4j@noreply.github.com
Cc: Alexei Chemenda alexei.chemenda@gmail.com
Subject: Re: [node-neo4j] Neo4j 1.6: support unique index "put if
absent"(#14)

I kinnda' fix it, for me.
You have to use neo4j 1.9, and small correction you have to do is in index
methods for node and relationship. Here is my change for the node index
method:

from line 204:
else {
var urlToPost = ((("" + services.node_index) + "/") + index +
'?uniqueness=create_or_fail');
/* 123 / return __this._request.post({
/ 124 */ url: urlToPost,

/* 125 / json: {
/ 126 / key: key,
/ 127 / value: value,
/ 128 / uri: this.self
}
}, __cb(_, __frame, 17, 21, function ___(0, __4) {
/ 123 */ response = __4;
__then();
}, true));


Reply to this email directly or view it on GitHub
#14 (comment) .

@aseemk aseemk referenced this issue Aug 4, 2013
Closed

Unique node #84

@aseemk aseemk added a commit that closed this issue Oct 2, 2013
@aseemk aseemk Remove Node::indexUniquely() method.
This capability -- adding an *existing* node to an index unless one already
exists -- has been removed in 1.9. Sad day. =/

Thanks @flipside for both contributing this implementation and then giving a
heads-up that this is no longer possible.

Closes #14 -- we're going to have to wait til Neo4j 2.0's new indexing
framework, which will hopefully re-enable this (ideally via Cypher).
af6027e
@aseemk aseemk closed this in af6027e Oct 2, 2013
@aseemk
Member
aseemk commented Oct 2, 2013

In case you missed the notification, this feature was unfortunately removed from Neo4j 1.9, so we can't support it. Neo4j 2.0's auto-indexing improvements should make this automatic though.

@alexeichemenda

Thanks for the update ! I'll have a look pretty soon. 

Regards,


Alexei Chemenda
MotionLead - CoFounder
http://www.motionlead.com
+33.6.15.94.18.81

Sent from my iPhone

On Thu, Oct 3, 2013 at 12:00 AM, Aseem Kishore notifications@github.com
wrote:

In case you missed the notification, this feature was unfortunately removed from Neo4j 1.9, so we can't support it. Neo4j 2.0's auto-indexing improvements should make this automatic though.

Reply to this email directly or view it on GitHub:
#14 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment