cancel
Showing results for 
Search instead for 
Did you mean: 

How to check the node exists when the property type is array?

danbi5228
Node

Hi,
How do you check existence of the node if the property is type of array?

Before, I set the Product node's "vertical" property is 'string' type.
so I used like query below

match (w:Word)-[:SEARCH]->(c:Category)
with c
with collect(c)[0..5] as cs
return any(cat in cs where exists((cat)-[:INCLUDE]->(:Product {vertical: 'DEP'}))) as flag1,
any(cat in cs where exists((cat)-[:INCLUDE]->(:Product {vertical: 'OUT'}))) as flag2

but now, 'vertical' property is array type.
and this is impossible way (it's obvious)
any(cat in cs where exists((cat)-[:INCLUDE]->(:Product {'DEP' in vertical}))) as flag1,
any(cat in cs where exists((cat)-[:INCLUDE]->(:Product {'OUT' in vertical}))) as flag2

example query is the part of the whole cypher..
so I have to care about the cost of the cypher.
Please comment if you have any good idea

Thanks
Leila

1 ACCEPTED SOLUTION

giuseppe_villan
Graph Fellow

@danbi5228

I think that the following statement should be fine (I changed collect(c)[0..5] with WITH c LIMIT 5 and I collected vertical properties so that I can check only this property 😞

MATCH (w:Word)-[:SEARCH]->(c:Category)
WITH c LIMIT 5 // only 5 nodes
MATCH (c)-[:INCLUDE]->(p:Product) // match products
WITH collect(p.vertical) as verticals // collect verticals
RETURN any(vert in verticals where "DEP" in vert), any(vert in verticals where "OUT" in vert)

View solution in original post

2 REPLIES 2

giuseppe_villan
Graph Fellow

@danbi5228

I think that the following statement should be fine (I changed collect(c)[0..5] with WITH c LIMIT 5 and I collected vertical properties so that I can check only this property 😞

MATCH (w:Word)-[:SEARCH]->(c:Category)
WITH c LIMIT 5 // only 5 nodes
MATCH (c)-[:INCLUDE]->(p:Product) // match products
WITH collect(p.vertical) as verticals // collect verticals
RETURN any(vert in verticals where "DEP" in vert), any(vert in verticals where "OUT" in vert)

Thank you @giuseppe.villani !
I solve it thanks to your statement 😉

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.