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.

Missing property must stop the execution of the query?

gigauser
Graph Buddy

MATCH (s:Ingredient)-[r:COMMONLY_USED_TOGETHER]->(t:Ingredient)
RETURN id(s) as source, id(t) as target, r.score as weight

When this kind of query is executed even though there is no "score" property, it can make debugging more difficult if it is included in the bigger code like this:

MATCH (i:Ingredient)
WITH i.ingredient_community as community,count(*) as communitySize
ORDER BY communitySize DESC LIMIT 5
CALL gds.pageRank.stream({
nodeQuery:'MATCH (i:Ingredient) WHERE i.ingredient_community = $community
RETURN id(i) as id',
relationshipQuery:'MATCH (s:Ingredient)-[r:COMMONLY_USED_TOGETHER]->(t:Ingredient)
WHERE s.ingredient_community = $community AND t.ingredient_community = $community
RETURN id(s) as source, id(t) as target,r.score as weight',
relationshipWeightProperty:'weight',
parameters:{community:community}})
YIELD nodeId,score
WITH community, communitySize, nodeId, score
ORDER BY score DESC
RETURN community, communitySize, collect(gds.util.asNode(nodeId).name)[..3] as representatives

2 REPLIES 2

ameyasoft
Graph Maven
Try this:

MATCH (s:Ingredient)-[r:COMMONLY_USED_TOGETHER]->(t:Ingredient)
WHERE exists(r.score)
RETURN id(s) as source, id(t) as target, r.score as weight

Hi ameya,
Thank you for the reply.
I know we can do the query like that. My concern is Neo4j Cypher interpreter(or compiler?) could do better if there isn't a property in the graph at all.
Currently it displays a warning tells there is no property like that but it execute the query.
Up to that point it would be not so bad. But if that query(using a property not exist) is included in the other query like above then it doesn't display no warning. It can make debugging very difficult sometimes.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online