Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion cypher query to connect a where clause with the elements of an array

Received: by 10.66.85.105 with SMTP id g9mr4250177paz.18.1352459514219;
        Fri, 09 Nov 2012 03:11:54 -0800 (PST)
X-BeenThere: neo4j@googlegroups.com
Received: by 10.68.190.100 with SMTP id gp4ls15425959pbc.9.gmail; Fri, 09 Nov
 2012 03:11:52 -0800 (PST)
Received: by 10.68.143.74 with SMTP id sc10mr2468798pbb.5.1352459512708;
        Fri, 09 Nov 2012 03:11:52 -0800 (PST)
Date: Fri, 9 Nov 2012 03:11:52 -0800 (PST)
From: divyanshu das <divyanshu....@gmail.com>
To: neo4j@googlegroups.com
Message-Id: <4a9fcbb2-4fed-4e50-afc5-ded89b436fa6@googlegroups.com>
In-Reply-To: <f4de12ea-3db0-466f-99f0-e533076d93fa@googlegroups.com>
References: <7b4f7d5e-7f1d-4a7d-a93f-9e840a88aa86@googlegroups.com>
 <CAAOkgHMLHXePFADo7RQQFdugXEHeuaNeXyo=Gf69jCs0ROEq0g@mail.gmail.com>
 <CAAOkgHPW0TXdtNwvYwp7G7vSeaATbVDseaukrZtWKnyN3+NUyw@mail.gmail.com>
 <f8a6dacf-a1f5-4eda-bf1c-dc24e1a00502@googlegroups.com> <be1f9e15-8c04-4a42-a419-9063cfb5046a@googlegroups.com>
 <CAAOkgHN0w_ZLfch6=nFyYUxHBYtnNtDrM1jrMLyne8fe9AKF9Q@mail.gmail.com>
 <baa21a00-9ed5-43ad-a995-6108992d8f30@googlegroups.com> <CADLsmuuxah1pFxG4+ZVBKo2jHqUn47dnGxjpehw+jU198urNgA@mail.gmail.com>
 <9139b435-859f-4b3f-be84-e4e6de219099@googlegroups.com> <CAAOkgHM3yrUWETVRWmbzb3TKx2Vs8jTMkFEUeDvLJ=j+yLp6_w@mail.gmail.com>
 <8ad9e2c4-cc2c-45b3-a85e-64a7caa6dc03@googlegroups.com>
 <CAAOkgHMzsnsN447xceSfjQbH=NkxKhbzS5x9j-zwURxU4B8YTA@mail.gmail.com>
 <f4de12ea-3db0-466f-99f0-e533076d93fa@googlegroups.com>
Subject: Re: [Neo4j] cypher query to connect a where clause with the
 elements of an array
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_139_150628.1352459512133"

------=_Part_139_150628.1352459512133
Content-Type: multipart/alternative; 
	boundary="----=_Part_140_15033689.1352459512134"

------=_Part_140_15033689.1352459512134
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Ok. so finally the query the completed, and shows me the desired results if 
I specify node numbers. 

But it fails for node(8). I am assuming its some memory management issue. 
Right now, I dont have time to get into this. 

Can someone tell me, how do I pass an array or list as an argument for 
start node. Something like,

start n = node(array of nodes)
Since I am already passing an array, so it will be second array. Is paasing 
of two arrays allowed in the same query?

On Friday, 9 November 2012 02:12:45 UTC+5:30, divyanshu das wrote:
>
> the database is designed in a way that, if a node has "rel" relationship 
> it'll have "prop" property too.
>
> has(n.prop) is just to check if starting node has "prop" property.
>
> On Friday, 9 November 2012 01:55:24 UTC+5:30, Wes Freeman wrote:
>>
>> Your queries might be mixing up the "n" and "b" identifiers. I think you 
>> mean:
>> "has(b.prop) and not(b.prop in {phparr})"
>>
>> Wes
>>
>> On Thu, Nov 8, 2012 at 3:19 PM, divyanshu das <divyan...@gmail.com>wrote:
>>
>>> Yes, I do have indexes. 
>>>
>>> this is the query I am using:- $queryTemplate = "START n = node(*) MATCH 
>>> n-[:rel]->b WHERE has(n.prop) AND not(b.prop in {phparr}) RETURN b";
>>> phparr is one single array.
>>>
>>> Ideally this query should return all the list of nodes "b" , which has a 
>>> "rel" relationship and b.prop is not an element of array.
>>> But it gives the error I pasted earlier
>>>
>>> If I use this query:- $queryTemplate = "START n = node(1239147) MATCH 
>>> n-[:rel]->b WHERE (n.prop in {phparr}) RETURN b";
>>>
>>> I get nodes with b.prop in the array.
>>>
>>> But when I use this query with a "not" in where clause it gives no 
>>> results. I have tried it with 10 nodes. everytime zero results.
>>>
>>> My db has 6 million nodes, and 1645 have property "prop"
>>>
>>>
>>> On Friday, 9 November 2012 01:21:33 UTC+5:30, Wes Freeman wrote:
>>>
>>>> It will. David is just saying (in response to the question about how to 
>>>> delete in cypher, earlier in the thread) that if you have indexes on those 
>>>> nodes (do you?), you should query the indexes on the particular fields that 
>>>> are indexed so the indexes get cleaned up, afterward. You also need to 
>>>> delete the relationships connected to those nodes at the same time (else 
>>>> you'll get an error about not being able to delete nodes with 
>>>> relationships), so you might end up with something like "match n-[r?]-() 
>>>> ... delete n,r;"
>>>>
>>>> I'm not sure what the PHP error is coming from--I'm not much of a PHP 
>>>> guy, myself. Is this a single command that's failing after 10 minutes, or 
>>>> are you iterating through some list of arrays and it's failing on one of 
>>>> the particular arrays?
>>>>
>>>> On Thu, Nov 8, 2012 at 1:42 PM, divyanshu das <divyan...@gmail.com>wrote:
>>>>
>>>>> thnx for pointing this out. But I did not quite understand it. Does 
>>>>> this mean, that if I replace "return" by "delete" it wont delete the nodes?
>>>>>
>>>>> However, right now, I  want to return those nodes first so that I can 
>>>>> check if I am actually deleting the right node.
>>>>>
>>>>>
>>>>> On Friday, 9 November 2012  00:03:03 UTC+5:30, David Montag wrote:
>>>>>
>>>>>> Just want to jump in here. The current workaround for deleting 
>>>>>> indexed nodes with Cypher requires you to know what indexes the node is 
>>>>>> indexed in, and for which property keys and values it is indexed. You can 
>>>>>> then delete the node, and then look it up in all indexes where it was 
>>>>>> previously indexed. This will not return any results, but it will trigger 
>>>>>> the necessary cleanup of the index.
>>>>>>  
>>>>>> David
>>>>>>
>>>>>>
>>>>>> On Wed, Nov 7, 2012 at 1:36 PM, divyanshu das <divyan...@gmail.com>wrote:
>>>>>>
>>>>>>> Is there any other way to delete nodes in 1.6.1 without using cypher 
>>>>>>> queries?
>>>>>>>
>>>>>>>
>>>>>>> On Thursday, 8 November 2012 02:56:56 UTC+5:30, Wes Freeman wrote:
>>>>>>>
>>>>>>>> It isn't a good idea to depend on node ids for long term use 
>>>>>>>> (rather, use an email address or guid or similar unique id, with an index). 
>>>>>>>> Ids are reused after you restart the server, I think, if they were deleted.
>>>>>>>>
>>>>>>>> Wes
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Nov 7, 2012 at 4:18 PM, divyanshu das <divyan...@gmail.com>wrote:
>>>>>>>>
>>>>>>>>> If I upgrade to 1.8, then I get the delete queries. Now, If I 
>>>>>>>>> delete the nodes, will the node ids for other users remain unchanged or 
>>>>>>>>> neo4j automatically reuses the deleted ids?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Thursday, 8 November 2012 02:42:51 UTC+5:30, divyanshu das 
>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>> Hey, thanks for prompt replies. If I am correct, node(*) method 
>>>>>>>>>> is not available in 1.6.1. Any workaround  for this?
>>>>>>>>>>
>>>>>>>>>> On Thursday, 8 November 2012 02:40:29 UTC+5:30, Wes Freeman wrote:
>>>>>>>>>>>
>>>>>>>>>>> I guess that's not exactly what you asked for... how about this:
>>>>>>>>>>>
>>>>>>>>>>> http://console.neo4j.org/r/**xg5******y9u<http://console.neo4j.org/r/xg5y9u>
>>>>>>>>>>>
>>>>>>>>>>> start n=node(*) 
>>>>>>>>>>> match n-[:rel]->() 
>>>>>>>>>>> where has(n.arr) and not(n.prop in n.arr) 
>>>>>>>>>>> return n;
>>>>>>>>>>>
>>>>>>>>>>> On Wed, Nov 7, 2012 at 3:54 PM, Wes Freeman <freem...@gmail.com>wrote:
>>>>>>>>>>>
>>>>>>>>>>>> You can't delete via Cypher with that version of Neo. 
>>>>>>>>>>>>
>>>>>>>>>>>> If you want to just find them, you could do something like (I'm 
>>>>>>>>>>>> not entirely sure this worked back then, either--you might consider 
>>>>>>>>>>>> upgrading):
>>>>>>>>>>>>
>>>>>>>>>>>> start n=node(*)
>>>>>>>>>>>> where n.prop in n.arr
>>>>>>>>>>>> return n;
>>>>>>>>>>>>
>>>>>>>>>>>> Wes
>>>>>>>>>>>>
>>>>>>>>>>>> On Wed, Nov 7, 2012 at 3:43 PM, divyanshu das <
>>>>>>>>>>>> divyan...@gmail.com> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> I have neo4j 1.6.1 and I am using php .
>>>>>>>>>>>>>
>>>>>>>>>>>>> I have an array "arr" of a particular property "prop" of nodes.
>>>>>>>>>>>>>
>>>>>>>>>>>>> I want to delete all nodes from neo4j having a certain 
>>>>>>>>>>>>> relationship "rel" except for the nodes whose property "prop" is in the 
>>>>>>>>>>>>> array "arr".
>>>>>>>>>>>>>
>>>>>>>>>>>>> Can somebody help me out with this? 
>>>>>>>>>>>>>  
>>>>>>>>>>>>> -- 
>>>>>>>>>>>>>  
>>>>>>>>>>>>>  
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>  -- 
>>>>>>>>>  
>>>>>>>>>  
>>>>>>>>>
>>>>>>>>
>>>>>>>>  -- 
>>>>>>>  
>>>>>>>  
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> -- 
>>>>>> David Montag <david....@**neotechnolog**y.com>
>>>>>> Neo Technology, www.neotechnology.****com<http://www.neotechnology.com/>
>>>>>> Cell: 650.556.4411
>>>>>> Skype: ddmontag
>>>>>>  
>>>>>  -- 
>>>>>  
>>>>>  
>>>>>
>>>>
>>>>  -- 
>>>  
>>>  
>>>
>>
>>
------=_Part_140_15033689.1352459512134
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Ok. so finally the query the completed, and shows me the desired results if=
 I specify node numbers.&nbsp;<div><br></div><div>But it fails for node(8).=
 I am assuming its some memory management issue. Right now, I dont have tim=
e to get into this.&nbsp;</div><div><br></div><div>Can someone tell me, how=
 do I pass an array or list as an argument for start node. Something like,<=
/div><div><br></div><div>start n =3D node(array of nodes)</div><div>Since I=
 am already passing an array, so it will be second array. Is paasing of two=
 arrays allowed in the same query?</div><div><br>On Friday, 9 November 2012=
 02:12:45 UTC+5:30, divyanshu das  wrote:<blockquote class=3D"gmail_quote" =
style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-l=
eft: 1ex;">the database is designed in a way that, if a node has "rel" rela=
tionship it'll have "prop" property too.<div><br></div><div>has(n.prop) is =
just to check if starting node has "prop" property.<br><br>On Friday, 9 Nov=
ember 2012 01:55:24 UTC+5:30, Wes Freeman  wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">Your queries might be mixing up the "n" and "b" identifiers. =
I think you mean:<div>"has(b.prop) and not(b.prop in {phparr})"<br><br>Wes<=
br><div><br><div class=3D"gmail_quote">

On Thu, Nov 8, 2012 at 3:19 PM, divyanshu das <span dir=3D"ltr">&lt;<a>divy=
an...@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" =
style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Yes, I do have indexes.&nbsp;<div><br></div><div>this is the query I am usi=
ng:-&nbsp;$queryTemplate =3D "START n =3D node(*) MATCH n-[:rel]-&gt;b WHER=
E has(n.prop) AND not(b.prop in {phparr}) RETURN b";<br>phparr is one singl=
e array.</div>

<div><br></div><div>Ideally this query should return all the list of nodes =
"b" , which has a "rel" relationship and b.prop is not an element of array.=
</div><div>But it gives the error I pasted earlier</div>

<div><br></div><div>If I use this query:-&nbsp;$queryTemplate =3D "START n =
=3D node(1239147) MATCH n-[:rel]-&gt;b WHERE (n.prop in {phparr}) RETURN b"=
;</div><div><br></div><div>I get nodes with b.prop in the array.</div>

<div><br></div><div>But when I use this query with a "not" in where clause =
it gives no results. I have tried it with 10 nodes. everytime zero results.=
</div><div><br></div><div>My db has 6 million nodes, and 1645 have property=
 "prop"</div>

<div><br></div><div><div><br>On Friday, 9 November 2012 01:21:33 UTC+5:30, =
Wes Freeman  wrote:</div><blockquote class=3D"gmail_quote" style=3D"margin:=
0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><div>It will. David is just saying (in response to the question about =
how to delete in cypher, earlier in the thread) that if you have indexes on=
 those nodes (do you?), you should query the indexes on the particular fiel=
ds that are indexed so the indexes get cleaned up, afterward. You also need=
 to delete the relationships connected to those nodes at the same time (els=
e you'll get an error about not being able to delete nodes with relationshi=
ps), so you might end up with something like "match n-[r?]-() ... delete n,=
r;"</div>



<div><br></div><div>I'm not sure what the PHP error is coming from--I'm not=
 much of a PHP guy, myself. Is this a single command that's failing after 1=
0 minutes, or are you iterating through some list of arrays and it's failin=
g on one of the particular arrays?</div>



<br></div><div><div><div><div class=3D"gmail_quote">On Thu, Nov 8, 2012 at =
1:42 PM, divyanshu das <span dir=3D"ltr">&lt;<a>divyan...@gmail.com</a>&gt;=
</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">thnx for pointing this out. But I did not qu=
ite understand it. Does this mean, that if I replace "return" by "delete" i=
t wont delete the nodes?<div>



<br></div><div>However, right now, I &nbsp;want to return those nodes first=
 so that I can check if I am actually deleting the right node.<div><br><br>=
On Friday, 9 November 2012 &nbsp;00:03:03 UTC+5:30, David Montag  wrote:</d=
iv>

<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;borde=
r-left:1px #ccc solid;padding-left:1ex"><div>Just want to jump in here. The=
 current workaround for deleting indexed nodes with Cypher requires you to =
know what indexes the node is indexed in, and for which property keys and v=
alues it is indexed. You can then delete the node, and then look it up in a=
ll indexes where it was previously indexed. This will not return any result=
s, but it will trigger the necessary cleanup of the index.</div>



<div>

<div><br></div><div>David<div><div><br><br><div class=3D"gmail_quote">On We=
d, Nov 7, 2012 at 1:36 PM, divyanshu das <span dir=3D"ltr">&lt;<a>divyan...=
@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">Is there any other way to delete nodes in 1.=
6.1 without using cypher queries?<div><br><br>On Thursday, 8 November 2012 =
02:56:56 UTC+5:30, Wes Freeman  wrote:</div>





<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;borde=
r-left:1px #ccc solid;padding-left:1ex"><div>It isn't a good idea to depend=
 on node ids for long term use (rather, use an email address or guid or sim=
ilar unique id, with an index). Ids are reused after you restart the server=
, I think, if they were deleted.<div>





<br>

</div></div><div>Wes<div><div><br><div><br><div class=3D"gmail_quote">On We=
d, Nov 7, 2012 at 4:18 PM, divyanshu das <span dir=3D"ltr">&lt;<a>divyan...=
@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex">If I upgrade to 1.8, then I get the delete q=
ueries. Now, If I delete the nodes, will the node ids for other users remai=
n unchanged or neo4j automatically reuses the deleted ids?<div>







<div><br><br>On Thursday, 8 November 2012 02:42:51 UTC+5:30, divyanshu das =
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8e=
x;border-left:1px #ccc solid;padding-left:1ex">Hey, thanks for prompt repli=
es. If I am correct, node(*) method is not available in 1.6.1. Any workarou=
nd &nbsp;for this?<br>







<br>On Thursday, 8 November 2012 02:40:29 UTC+5:30, Wes Freeman  wrote:<blo=
ckquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-le=
ft:1px #ccc solid;padding-left:1ex"><div>I guess that's not exactly what yo=
u asked for... how about this:<br>







<br></div><div><a href=3D"http://console.neo4j.org/r/xg5y9u" target=3D"_bla=
nk">http://console.neo4j.org/r/<u></u>xg5<u></u><u></u><u></u><wbr>y9u</a><=
br></div><div><br></div><div><div>start n=3Dnode(*)&nbsp;</div>

<div>match n-[:rel]-&gt;()&nbsp;</div><div>where has(n.arr) and not(n.prop =
in n.arr)&nbsp;</div><div>return n;</div></div><br><div><div class=3D"gmail=
_quote">On Wed, Nov 7, 2012 at 3:54 PM, Wes Freeman <span dir=3D"ltr">&lt;<=
a>freem...@gmail.com</a>&gt;</span> wrote:<br>









<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">You can't delete via Cypher with that version of Neo.&nbsp=
;<div>









<br></div><div>If you want to just find them, you could do something like (=
I'm not entirely sure this worked back then, either--you might consider upg=
rading):</div>
<div><br>start n=3Dnode(*)<br>where n.prop in n.arr<br>return n;<br><div><b=
r></div><div>Wes</div><div><div><div><br><div class=3D"gmail_quote">On Wed,=
 Nov 7, 2012 at 3:43 PM, divyanshu das <span dir=3D"ltr">&lt;<a>divyan...@g=
mail.com</a>&gt;</span> wrote:<br>










<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex"><div>I have neo4j 1.6.1 and I am using php .</div><div><br=
>









</div>I have an array "arr" of a particular property "prop" of nodes.<div>
<br></div><div>I want to delete all nodes from neo4j having a certain relat=
ionship "rel" except for the nodes whose property "prop" is in the array "a=
rr".</div><div><br></div><div>Can somebody help me out with this?&nbsp;</di=
v>










<span><font color=3D"#888888">

<p></p>

-- <br>
&nbsp;<br>
&nbsp;<br>
</font></span></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>
</blockquote></blockquote>

<p></p>

-- <br>
&nbsp;<br>
&nbsp;<br>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote>

<p></p>

-- <br>
&nbsp;<br>
&nbsp;<br>
</blockquote></div><br><br clear=3D"all"><div><br></div>-- <br></div></div>=
<div>David Montag&nbsp;&lt;<a>david....@<u></u>neotechnolog<u></u><wbr>y.co=
m</a>&gt;</div><div><div>Neo Technology,&nbsp;<a href=3D"http://www.neotech=
nology.com/" target=3D"_blank">www.neotechnology.<u></u><u></u><wbr>com</a>=
</div>





<div>Cell: <a value=3D"+16505564411">650.556.4411</a></div>Skype: ddmontag<=
br>
</div></div></div>
</blockquote></div>

<p></p>

-- <br>
&nbsp;<br>
&nbsp;<br>
</blockquote></div><br></div>
</div></div></blockquote></div>

<p></p>

-- <br>
&nbsp;<br>
&nbsp;<br>
</blockquote></div><br></div></div>
</blockquote></div></blockquote></div>
------=_Part_140_15033689.1352459512134--

------=_Part_139_150628.1352459512133--