cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Query float attribute on a relationship

I have defined properties probability and attr for a relation as below:

:START_ID;role;:END_ID;:TYPE;probability;attr:float

keanu;'Neo';tt0133093;ACTED_IN;0.1;0.1

keanu;'Neo';tt0234215;ACTED_IN;0.2;0.2

keanu;'Neo';tt0242653;ACTED_IN;0.3;0.3

laurence;'Morpheus';tt0133093;ACTED_IN;0.4;0.4

laurence;'Morpheus';tt0234215;ACTED_IN;0.5;0.5

laurence;'Morpheus';tt0242653;ACTED_IN;0.6;0.6

carrieanne;'Trinity';tt0133093;ACTED_IN;0.7;0.7

carrieanne;'Trinity';tt0234215;ACTED_IN;0.8;0.8

carrieanne;'Trinity';tt0242653;ACTED_IN;0.9;0.9

How can I query this relation the has a attr > 0.35 in cypher ?

Thanks,

Ravi.

1 ACCEPTED SOLUTION

couple of concerns here.
Your cypher of

MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN {role :'Trinity', attr> 0.7}]-() RETURN a,r;

not sure what the initial MATCH (n) is providing. It basically says traverse the entire graph and alias each node to variable n. But then n is never used again. Not sure I see the need for this.

Regarding your I could not get the following query to work, i get syntax errors: although not stated, I presume you are getting errors similar to

neo4j> MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN {role :'Trinity', attr> 0.7}]-() RETURN a,r;
Invalid input '>': expected an identifier character, whitespace or ':' (line 1, column 86 (offset: 85))
"MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN {role :'Trinity', attr> 0.7}]-() RETURN a,r;"

is that correct? Is this the error you receive? If not what error do you receive?
If this is the error you get then this is because the expression at {role :'Trinity', attr> 0.7} needs to be a JSON statement. As JSON does not support a > the alternative would be

MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN]-() where r.role='Trinity' and r.attr>0.7 RETURN a,r;

though again in this case I'm not sure of the 'MATCH (n)` and what benefit it serves

View solution in original post

3 REPLIES 3

what have you tried so far? Are you not getting expected results?

I would suspect a

where attr>0.35  

should suffice

I could not get the following query to work, i get syntax errors:

MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN {role :'Trinity', attr> 0.7}]-() RETURN a,r;

Please suggest a fix.

thanks,

Ravi.

couple of concerns here.
Your cypher of

MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN {role :'Trinity', attr> 0.7}]-() RETURN a,r;

not sure what the initial MATCH (n) is providing. It basically says traverse the entire graph and alias each node to variable n. But then n is never used again. Not sure I see the need for this.

Regarding your I could not get the following query to work, i get syntax errors: although not stated, I presume you are getting errors similar to

neo4j> MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN {role :'Trinity', attr> 0.7}]-() RETURN a,r;
Invalid input '>': expected an identifier character, whitespace or ':' (line 1, column 86 (offset: 85))
"MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN {role :'Trinity', attr> 0.7}]-() RETURN a,r;"

is that correct? Is this the error you receive? If not what error do you receive?
If this is the error you get then this is because the expression at {role :'Trinity', attr> 0.7} needs to be a JSON statement. As JSON does not support a > the alternative would be

MATCH (n) MATCH (a:Actor{name:'Carrie-Anne Moss'})-[r:ACTED_IN]-() where r.role='Trinity' and r.attr>0.7 RETURN a,r;

though again in this case I'm not sure of the 'MATCH (n)` and what benefit it serves