Re: [Neo4j] Update/Move relationships through REST APIs
Thanks! On Wed, Aug 31, 2011 at 6:50 PM, Marko Rodriguez wrote: > Hey, > > One more thing. > > WARNING: If your transaction mode is AUTOMATIC, then there will be one > transaction for each mutation !! tx.begin/tx.commit/tx.finish > > gremlin> g.transactionMode > ==>AUTOMATIC > > You can use a transaction manager if you plan this query to iterate over > lots of vertices and do lots of mutations: > > https://github.com/tinkerpop/blueprints/wiki/Graph-Transactions-Helpers > > Thus, your mutating traversal would be: > >manager = TransactionalGraphHelper.createCommitManager(g, 1000); >g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo'); > g.removeEdge(it); manager.incrCounter()} >manager.close(); > > Hope that helps -- and doesn't confuse :). > > Marko. > http://markorodriguez.com > > P.S. Gremlin 1.3 will make it much more natural to do batch transactions. > TransactionGraphs (like Neo4j) will have a "setTransactionBuffer(int > bufferSize)" method so you don't need to create this CommitManager object. > Anywho. Thats that. See ya. > > On Aug 31, 2011, at 7:38 PM, Marko Rodriguez wrote: > > > Hi, > > > > I did you example over TinkerGraph as vertex IDs are Strings and thus, > easy to build your graph with. > > > > ~$ gremlin > > \,,,/ > > (o o) > > -oOOo-(_)-oOOo- > > gremlin> g = new TinkerGraph() > > ==>tinkergraph[vertices:0 edges:0] > > gremlin> g.addVertex('A'); g.addVertex('B'); g.addVertex('C'); > g.addVertex('D'); g.addVertex('E'); > > ==>v[E] > > gremlin> g.addEdge(g.v('C'),g.v('A'),'foo'); > g.addEdge(g.v('D'),g.v('A'),'foo'); g.addEdge(g.v('E'),g.v('A'),'bar') > > ==>e[2][E-bar->A] > > gremlin> g.V > > ==>v[D] > > ==>v[E] > > ==>v[A] > > ==>v[B] > > ==>v[C] > > gremlin> g.E > > ==>e[2][E-bar->A] > > ==>e[1][D-foo->A] > > ==>e[0][C-foo->A] > > > > So, you have your 5 vertices and 3 edges. Next, here is your mutating > traversal: > > > > gremlin> > g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo'); > g.removeEdge(it)} > > ==>e[1][D-foo->A] > > ==>e[0][C-foo->A] > > > > And now your edges are as you wanted them. > > > > gremlin> g.E > > ==>e[3][D-foo->B] > > ==>e[2][E-bar->A] > > ==>e[4][C-foo->B] > > > > So again, your traversal is: > > > > g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo'); > g.removeEdge(it)} > > > > Here is what the traversal says step-by-step: > > > > g.V : iterate through all vertices > > outE('foo') : iterate through their the outgoing 'foo' labeled > edges > > sideEffect{} : yield a sideEffect (mutate state) > > g.addEdge(it.outVertex,g.v('B'),'foo'): add a new edge from > the vertex (e.g. C,D,E -- it.outVertex) to vertex B with label 'foo'. > > g.removeEdge(it) : remove the current edge (it) > > > > > > Note that its more optimal to do: > > > > v = g.v('B'); > g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,v,'foo'); > g.removeEdge(it)} > > > > Also, vertex IDs are not Strings in Neo4j, but longs. Hopefully you can > do what you need from here. > > > > Good luck, > > Marko. > > > > http://markorodriguez.com > > > > On Aug 31, 2011, at 6:17 PM, Nuo Yan wrote: > > > >> I want to update the ending node for all relationships that are type > :foo > >> coming into node A to node B. > >> > >> For example, for all relationships that are type :foo coming into node A > >> (node A as the end node), no matter where their starting node is, I want > >> them to set the end node to node B. > >> > >> Node C --:foo--> Node A > >> Node D --:foo--> Node A > >> Node E --:bar--> Node A > >> > >> would become: > >> > >> Node C --:foo--> Node B > >> Node D --:foo -> Node B > >> Node E --:bar--> Node A > >> > >> On Wed, Aug 31, 2011 at 5:00 PM, Marko Rodriguez >wrote: > >> > >>> Hi, > >>> > >>> If you tell me in English what you want to do, I can give you the > Gremlin > >>> query. With Gremlin, you can traverse and update in a single query so > >>> perhaps it will meet your needs. > >>> > >>> Marko. > >>> > >>> http://markorodriguez.com > >>> > >>> On Aug 31, 2011, at 5:13 PM, Nuo Yan wrote: > >>> > I looked through the REST APIs and didn't see an endpoint to move > relationships. Is such operation possible? For example, given a set of > relationships all end in one node, I want to send a bulk request to > >>> update > their end nodes to another node. > > If there is no REST API for updating/moving relationship, what is the > >>> best > way to do this? Can gremlin do it easily? Or do I have to delete all > of > >>> the > relationships and create new ones to the new end node? > > Thanks, > Nuo > ___ > Neo4j mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user > >>> > >>> ___ > >>> Neo4j mailing list > >>> User@lists.neo4j.org > >>> https://lists.neo4j.org/mai
Re: [Neo4j] Update/Move relationships through REST APIs
Hey, One more thing. WARNING: If your transaction mode is AUTOMATIC, then there will be one transaction for each mutation !! tx.begin/tx.commit/tx.finish gremlin> g.transactionMode ==>AUTOMATIC You can use a transaction manager if you plan this query to iterate over lots of vertices and do lots of mutations: https://github.com/tinkerpop/blueprints/wiki/Graph-Transactions-Helpers Thus, your mutating traversal would be: manager = TransactionalGraphHelper.createCommitManager(g, 1000); g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo'); g.removeEdge(it); manager.incrCounter()} manager.close(); Hope that helps -- and doesn't confuse :). Marko. http://markorodriguez.com P.S. Gremlin 1.3 will make it much more natural to do batch transactions. TransactionGraphs (like Neo4j) will have a "setTransactionBuffer(int bufferSize)" method so you don't need to create this CommitManager object. Anywho. Thats that. See ya. On Aug 31, 2011, at 7:38 PM, Marko Rodriguez wrote: > Hi, > > I did you example over TinkerGraph as vertex IDs are Strings and thus, easy > to build your graph with. > > ~$ gremlin > \,,,/ > (o o) > -oOOo-(_)-oOOo- > gremlin> g = new TinkerGraph() > ==>tinkergraph[vertices:0 edges:0] > gremlin> g.addVertex('A'); g.addVertex('B'); g.addVertex('C'); > g.addVertex('D'); g.addVertex('E'); > ==>v[E] > gremlin> g.addEdge(g.v('C'),g.v('A'),'foo'); > g.addEdge(g.v('D'),g.v('A'),'foo'); g.addEdge(g.v('E'),g.v('A'),'bar') > > ==>e[2][E-bar->A] > gremlin> g.V > ==>v[D] > ==>v[E] > ==>v[A] > ==>v[B] > ==>v[C] > gremlin> g.E > ==>e[2][E-bar->A] > ==>e[1][D-foo->A] > ==>e[0][C-foo->A] > > So, you have your 5 vertices and 3 edges. Next, here is your mutating > traversal: > > gremlin> g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo'); > g.removeEdge(it)} > ==>e[1][D-foo->A] > ==>e[0][C-foo->A] > > And now your edges are as you wanted them. > > gremlin> g.E > ==>e[3][D-foo->B] > ==>e[2][E-bar->A] > ==>e[4][C-foo->B] > > So again, your traversal is: > > g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo'); > g.removeEdge(it)} > > Here is what the traversal says step-by-step: > > g.V : iterate through all vertices > outE('foo') : iterate through their the outgoing 'foo' labeled edges > sideEffect{} : yield a sideEffect (mutate state) > g.addEdge(it.outVertex,g.v('B'),'foo'): add a new edge from the > vertex (e.g. C,D,E -- it.outVertex) to vertex B with label 'foo'. > > g.removeEdge(it) : remove the current edge (it) > > > Note that its more optimal to do: > > v = g.v('B'); > g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,v,'foo'); g.removeEdge(it)} > > Also, vertex IDs are not Strings in Neo4j, but longs. Hopefully you can do > what you need from here. > > Good luck, > Marko. > > http://markorodriguez.com > > On Aug 31, 2011, at 6:17 PM, Nuo Yan wrote: > >> I want to update the ending node for all relationships that are type :foo >> coming into node A to node B. >> >> For example, for all relationships that are type :foo coming into node A >> (node A as the end node), no matter where their starting node is, I want >> them to set the end node to node B. >> >> Node C --:foo--> Node A >> Node D --:foo--> Node A >> Node E --:bar--> Node A >> >> would become: >> >> Node C --:foo--> Node B >> Node D --:foo -> Node B >> Node E --:bar--> Node A >> >> On Wed, Aug 31, 2011 at 5:00 PM, Marko Rodriguez wrote: >> >>> Hi, >>> >>> If you tell me in English what you want to do, I can give you the Gremlin >>> query. With Gremlin, you can traverse and update in a single query so >>> perhaps it will meet your needs. >>> >>> Marko. >>> >>> http://markorodriguez.com >>> >>> On Aug 31, 2011, at 5:13 PM, Nuo Yan wrote: >>> I looked through the REST APIs and didn't see an endpoint to move relationships. Is such operation possible? For example, given a set of relationships all end in one node, I want to send a bulk request to >>> update their end nodes to another node. If there is no REST API for updating/moving relationship, what is the >>> best way to do this? Can gremlin do it easily? Or do I have to delete all of >>> the relationships and create new ones to the new end node? Thanks, Nuo ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user >>> >>> ___ >>> Neo4j mailing list >>> User@lists.neo4j.org >>> https://lists.neo4j.org/mailman/listinfo/user >>> >> ___ >> Neo4j mailing list >> User@lists.neo4j.org >> https://lists.neo4j.org/mailman/listinfo/user > ___ N
Re: [Neo4j] Update/Move relationships through REST APIs
Hi, I did you example over TinkerGraph as vertex IDs are Strings and thus, easy to build your graph with. ~$ gremlin \,,,/ (o o) -oOOo-(_)-oOOo- gremlin> g = new TinkerGraph() ==>tinkergraph[vertices:0 edges:0] gremlin> g.addVertex('A'); g.addVertex('B'); g.addVertex('C'); g.addVertex('D'); g.addVertex('E'); ==>v[E] gremlin> g.addEdge(g.v('C'),g.v('A'),'foo'); g.addEdge(g.v('D'),g.v('A'),'foo'); g.addEdge(g.v('E'),g.v('A'),'bar') ==>e[2][E-bar->A] gremlin> g.V ==>v[D] ==>v[E] ==>v[A] ==>v[B] ==>v[C] gremlin> g.E ==>e[2][E-bar->A] ==>e[1][D-foo->A] ==>e[0][C-foo->A] So, you have your 5 vertices and 3 edges. Next, here is your mutating traversal: gremlin> g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo'); g.removeEdge(it)} ==>e[1][D-foo->A] ==>e[0][C-foo->A] And now your edges are as you wanted them. gremlin> g.E ==>e[3][D-foo->B] ==>e[2][E-bar->A] ==>e[4][C-foo->B] So again, your traversal is: g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo'); g.removeEdge(it)} Here is what the traversal says step-by-step: g.V : iterate through all vertices outE('foo') : iterate through their the outgoing 'foo' labeled edges sideEffect{} : yield a sideEffect (mutate state) g.addEdge(it.outVertex,g.v('B'),'foo'): add a new edge from the vertex (e.g. C,D,E -- it.outVertex) to vertex B with label 'foo'. g.removeEdge(it) : remove the current edge (it) Note that its more optimal to do: v = g.v('B'); g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,v,'foo'); g.removeEdge(it)} Also, vertex IDs are not Strings in Neo4j, but longs. Hopefully you can do what you need from here. Good luck, Marko. http://markorodriguez.com On Aug 31, 2011, at 6:17 PM, Nuo Yan wrote: > I want to update the ending node for all relationships that are type :foo > coming into node A to node B. > > For example, for all relationships that are type :foo coming into node A > (node A as the end node), no matter where their starting node is, I want > them to set the end node to node B. > > Node C --:foo--> Node A > Node D --:foo--> Node A > Node E --:bar--> Node A > > would become: > > Node C --:foo--> Node B > Node D --:foo -> Node B > Node E --:bar--> Node A > > On Wed, Aug 31, 2011 at 5:00 PM, Marko Rodriguez wrote: > >> Hi, >> >> If you tell me in English what you want to do, I can give you the Gremlin >> query. With Gremlin, you can traverse and update in a single query so >> perhaps it will meet your needs. >> >> Marko. >> >> http://markorodriguez.com >> >> On Aug 31, 2011, at 5:13 PM, Nuo Yan wrote: >> >>> I looked through the REST APIs and didn't see an endpoint to move >>> relationships. Is such operation possible? For example, given a set of >>> relationships all end in one node, I want to send a bulk request to >> update >>> their end nodes to another node. >>> >>> If there is no REST API for updating/moving relationship, what is the >> best >>> way to do this? Can gremlin do it easily? Or do I have to delete all of >> the >>> relationships and create new ones to the new end node? >>> >>> Thanks, >>> Nuo >>> ___ >>> Neo4j mailing list >>> User@lists.neo4j.org >>> https://lists.neo4j.org/mailman/listinfo/user >> >> ___ >> Neo4j mailing list >> User@lists.neo4j.org >> https://lists.neo4j.org/mailman/listinfo/user >> > ___ > Neo4j mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Update/Move relationships through REST APIs
I want to update the ending node for all relationships that are type :foo coming into node A to node B. For example, for all relationships that are type :foo coming into node A (node A as the end node), no matter where their starting node is, I want them to set the end node to node B. Node C --:foo--> Node A Node D --:foo--> Node A Node E --:bar--> Node A would become: Node C --:foo--> Node B Node D --:foo -> Node B Node E --:bar--> Node A On Wed, Aug 31, 2011 at 5:00 PM, Marko Rodriguez wrote: > Hi, > > If you tell me in English what you want to do, I can give you the Gremlin > query. With Gremlin, you can traverse and update in a single query so > perhaps it will meet your needs. > > Marko. > > http://markorodriguez.com > > On Aug 31, 2011, at 5:13 PM, Nuo Yan wrote: > > > I looked through the REST APIs and didn't see an endpoint to move > > relationships. Is such operation possible? For example, given a set of > > relationships all end in one node, I want to send a bulk request to > update > > their end nodes to another node. > > > > If there is no REST API for updating/moving relationship, what is the > best > > way to do this? Can gremlin do it easily? Or do I have to delete all of > the > > relationships and create new ones to the new end node? > > > > Thanks, > > Nuo > > ___ > > Neo4j mailing list > > User@lists.neo4j.org > > https://lists.neo4j.org/mailman/listinfo/user > > ___ > Neo4j mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user > ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Update/Move relationships through REST APIs
Hi, If you tell me in English what you want to do, I can give you the Gremlin query. With Gremlin, you can traverse and update in a single query so perhaps it will meet your needs. Marko. http://markorodriguez.com On Aug 31, 2011, at 5:13 PM, Nuo Yan wrote: > I looked through the REST APIs and didn't see an endpoint to move > relationships. Is such operation possible? For example, given a set of > relationships all end in one node, I want to send a bulk request to update > their end nodes to another node. > > If there is no REST API for updating/moving relationship, what is the best > way to do this? Can gremlin do it easily? Or do I have to delete all of the > relationships and create new ones to the new end node? > > Thanks, > Nuo > ___ > Neo4j mailing list > User@lists.neo4j.org > https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] Update/Move relationships through REST APIs
I looked through the REST APIs and didn't see an endpoint to move relationships. Is such operation possible? For example, given a set of relationships all end in one node, I want to send a bulk request to update their end nodes to another node. If there is no REST API for updating/moving relationship, what is the best way to do this? Can gremlin do it easily? Or do I have to delete all of the relationships and create new ones to the new end node? Thanks, Nuo ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user