For this one, the first problem I see is you're not specifying a label in
your match. Now that you have a super label, you can do this easily, and
take advantage of the index backing the constraint.

MATCH (x:MemberOfCompany {id: relationship.source_id}), (y:MemberOfCompany {id:
relationship.target_id})

On Fri, Feb 8, 2019 at 6:52 AM <andrea.balz...@keypartner.it> wrote:

> I just created a "super" label and a constraint on the id of its nodes.
> Just to make it more clear, at first  i had 16 labels (which could be
> represented by the roles of each person inside a company) and only one
> relationship between 2 different nodes (which is of only one kind, DIRECTS
> for example). The "super" label i created now is something like
> "MemberOfCompany" and added a constraint on it
>
> Should i add ON CREATE before SET and CALL the addLabels method or is it
> going to be redundant/disruptive?
>
> When i need to MERGE relationships this is the code i use
>
>         String query =
>                 "UNWIND $relationships AS relationship " +
>                 "MATCH (x {id: relationship.source_id}), (y {id:
> relationship.target_id}) " +
>                 "CALL apoc.merge.relationship(x, relationship.type,
> {source_id: relationship.source_id, target_id: relationship.target_id,
> type: relationship.type}, relationship, y) YIELD rel RETURN rel";
>         session.run( query, params );
>
> I'm suspecting this could be highly inefficient aswell, especially since i
> dont have a unique id for each relationship and i use a combo of source,
> target and type to determine its uniqueness. Is there anything here i could
> do differently to improve the efficiency and performances of this part?
>
> Thanks again
>
>
>
> Il giorno giovedì 7 febbraio 2019 22:47:16 UTC+1, eve.freema ha scritto:
>>
>> Sure thing. Let us know how it works out. :)
>>
>> On Thu, Feb 7, 2019 at 4:43 PM Andrea Balzoni <andrea....@keypartner.it>
>> wrote:
>>
>>> Thanks a lot for your input, i'll surely try what you suggested and add
>>> a constraint to my schema :)
>>>
>>> Thankd again for taking your time to answer
>>>
>>> Il giorno gio 7 feb 2019, 22:04 Eve Freeman <eve.f...@gmail.com> ha
>>> scritto:
>>>
>>>> Something like (these are totally untested, sorry for bugs)--also, this
>>>> label AllCategories should probably be more what your entities actually 
>>>> are:
>>>>
>>>> create constraint on (allCategories:AllCategories) assert
>>>> allCategories.id is unique;
>>>>
>>>> UNWIND $nodes AS n
>>>> MERGE (node:AllCategories {id: n.id})
>>>> SET node += n
>>>> RETURN node
>>>>
>>>> If you want to retain category as a label, you could add it in a second
>>>> part with something like:
>>>> UNWIND $nodes AS n
>>>> MERGE (node:AllCategories {id: n.id})
>>>> SET node += n
>>>> call apoc.create.addLabels([ id(node) ], [ n.category ]) yield node
>>>> RETURN node
>>>>
>>>> On Thu, Feb 7, 2019 at 3:52 PM Andrea Balzoni <andrea....@keypartner.it>
>>>> wrote:
>>>>
>>>>> Ids are supposed to be globally unique, regardless of their label
>>>>> (again, i'm not sure this is the best approach, but i thought it was the
>>>>> one that made more sense), i'm not sure what kind of info i could provide
>>>>> so feel free to ask...
>>>>>
>>>>> Il giorno gio 7 feb 2019, 21:24 Eve Freeman <eve.f...@gmail.com> ha
>>>>> scritto:
>>>>>
>>>>>> Whoops, "if so" should be "if not".
>>>>>>
>>>>>> On Thu, Feb 7, 2019 at 3:22 PM Eve Freeman <eve.f...@gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Are the ids unique to each label? If so, maybe you can merge on one
>>>>>>> "inclusive" label and then add an additional category label, and  then 
>>>>>>> you
>>>>>>> can have just one constraint. No idea what you're doing here, so giving 
>>>>>>> my
>>>>>>> best guess.
>>>>>>>
>>>>>>> On Thu, Feb 7, 2019 at 2:40 PM Andrea Balzoni <
>>>>>>> andrea....@keypartner.it> wrote:
>>>>>>>
>>>>>>>> That sounds like a lot of constraints or am i wrong?
>>>>>>>>
>>>>>>>> Il giorno gio 7 feb 2019, 20:19 Eve Freeman <eve.f...@gmail.com>
>>>>>>>> ha scritto:
>>>>>>>>
>>>>>>>>> Yes. You would need to add a constraint for each label + id
>>>>>>>>> combination.
>>>>>>>>>
>>>>>>>>> On Thu, Feb 7, 2019 at 1:57 PM Andrea Balzoni <
>>>>>>>>> andrea....@keypartner.it> wrote:
>>>>>>>>>
>>>>>>>>>> Sadly the ids i'm trying to add are not going to be necessarily
>>>>>>>>>> unique, hence why i'm using merge. I think i grasped what a 
>>>>>>>>>> constrant is,
>>>>>>>>>> but i cant say the same about indexes. So you are telling me that 
>>>>>>>>>> adding a
>>>>>>>>>> constraint on ids would make the query faster? Sorry about questions 
>>>>>>>>>> that
>>>>>>>>>> might sound stupid, but i'm fairly new to neo4j...
>>>>>>>>>>
>>>>>>>>>> Il giorno gio 7 feb 2019, 18:59 Eve Freeman <eve.f...@gmail.com>
>>>>>>>>>> ha scritto:
>>>>>>>>>>
>>>>>>>>>>> One other note--if you know these are unique ids, you can avoid
>>>>>>>>>>> using merge, and just use create, which will be quicker still.
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Feb 7, 2019 at 12:54 PM Eve Freeman <eve.f...@gmail.com>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Well, what a merge will do is check whether something exists
>>>>>>>>>>>> before it creates it, "match or create". The match step will get 
>>>>>>>>>>>> linearly
>>>>>>>>>>>> slower as it has to scan larger and larger lists of nodes on a 
>>>>>>>>>>>> label. If
>>>>>>>>>>>> you add an index (at minimum), or unique constraint/node key 
>>>>>>>>>>>> (preferred,
>>>>>>>>>>>> especially if you require uniqueness and will eventually have 
>>>>>>>>>>>> concurrent
>>>>>>>>>>>> requests of this nature), it will be able to do the match step much
>>>>>>>>>>>> quicker.
>>>>>>>>>>>>
>>>>>>>>>>>> On Thu, Feb 7, 2019 at 12:50 PM Andrea Balzoni <
>>>>>>>>>>>> andrea....@keypartner.it> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Honestly i heard of those, but i'm not using any. I'm quite
>>>>>>>>>>>>> new to it, so i wasnt sure what their purpose is.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Il giorno gio 7 feb 2019, 18:43 Eve Freeman <
>>>>>>>>>>>>> eve.f...@gmail.com> ha scritto:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> What's your schema? Do you have a unique constraint or index
>>>>>>>>>>>>>> on the labels + id you're merging on?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Eve
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Thu, Feb 7, 2019 at 12:23 PM <andrea....@keypartner.it>
>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hello everyone, i'm trying to MERGE thousands of nodes using
>>>>>>>>>>>>>>> UNWIND and apoc procedures (for a dynamic label creation) using 
>>>>>>>>>>>>>>> Java Driver
>>>>>>>>>>>>>>> as follows:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>         String query =
>>>>>>>>>>>>>>>                 "UNWIND $nodes AS n " +
>>>>>>>>>>>>>>>                 "CALL apoc.merge.node([n.category], {id:
>>>>>>>>>>>>>>> n.id}, n) YIELD node RETURN node";
>>>>>>>>>>>>>>>         session.run( query, params );
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> My database contains something like 150k nodes divided by 16
>>>>>>>>>>>>>>> labels and 130k relationships of the same type. It worked fine 
>>>>>>>>>>>>>>> so far, it
>>>>>>>>>>>>>>> never failed to deliver, but now that i'm trying to create 
>>>>>>>>>>>>>>> something like
>>>>>>>>>>>>>>> 4k new nodes and 5k new relationships at once it took more than 
>>>>>>>>>>>>>>> 30 minutes.
>>>>>>>>>>>>>>> I feel like it should be way faster than this.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Am i doing anything wrong? Is it really supposed to be this
>>>>>>>>>>>>>>> slow? Is there anything i can do to make this process smoother 
>>>>>>>>>>>>>>> and to
>>>>>>>>>>>>>>> improve performances?
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Thanks in advance
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>>>>>> Google Groups "Neo4j" group.
>>>>>>>>>>>>>>> To unsubscribe from this group and stop receiving emails
>>>>>>>>>>>>>>> from it, send an email to neo4j+un...@googlegroups.com.
>>>>>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>> --
>>>>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>>>>> Google Groups "Neo4j" group.
>>>>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>>>>>>>>> it, send an email to neo4j+un...@googlegroups.com.
>>>>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>>>>>
>>>>>>>>>>>>> --
>>>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>>>> Google Groups "Neo4j" group.
>>>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>>>>>>>> it, send an email to neo4j+un...@googlegroups.com.
>>>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>>> Google Groups "Neo4j" group.
>>>>>>>>>>> To unsubscribe from this group and stop receiving emails from
>>>>>>>>>>> it, send an email to neo4j+un...@googlegroups.com.
>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>> Google Groups "Neo4j" group.
>>>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>>>> send an email to neo4j+un...@googlegroups.com.
>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>>> Groups "Neo4j" group.
>>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>>> send an email to neo4j+un...@googlegroups.com.
>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>
>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>> Groups "Neo4j" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>> send an email to neo4j+un...@googlegroups.com.
>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>
>>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Neo4j" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to neo4j+un...@googlegroups.com.
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Neo4j" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to neo4j+un...@googlegroups.com.
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Neo4j" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to neo4j+un...@googlegroups.com.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Neo4j" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to neo4j+un...@googlegroups.com.
>>
>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to neo4j+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to neo4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to