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.

Is there a way to implement a function that filters for a variable number of predefined attributes with a respective minimum and maximum value?

Is there a way to implement a function that filters for a variable number of predefined attributes with a respective minimum and maximum value?

I can manage for a fixed number of attributes, but I want to keep the number variable. Something like:
information in a list :
dictionary1: attribute_name1 - min1 - max1
dictionary2: attribute_name 2 - min2 - max2
dictionary3: attribute3 - min3 - max3
-> filter for all elements where the attributes are in the given range
MATCH(a:node_label)
WHERE a.attribute1>min1 AND a.attribute1min2 AND a.attribute2min3 AND a.attribute3<max3
return a

it should also work if I only have these attributes in the list:
dictionary1: attribute1 - min1 - max1
dictionary2: attribute2 - min2 - max2
-> filter for all elements where the attributes are in the given range
MATCH(a:node_label)
WHERE a.attribute1>min1 AND a.attribute1min2 AND a.attribute2<max2
return a

or if there is a random number of dictionaries in the list

I tried it with unwind, but then I have only the attributes for one dictionary available at the same time to use it in WHERE. The problem is I need to connect the WHERE statement of all dictionary together...
Anyone an idea?

1 ACCEPTED SOLUTION

You can try the following if you want pure cypher. Define your list of constraints in the with clause.

with [{prop: 'x', min: 1, max: 3}, {prop: 'y', min: 10, max: 15}] as constraints
match(n:node_label)
where all(i in constraints where i.min <= n[i.prop] <= i.max)
return n

View solution in original post

2 REPLIES 2

You can try the following if you want pure cypher. Define your list of constraints in the with clause.

with [{prop: 'x', min: 1, max: 3}, {prop: 'y', min: 10, max: 15}] as constraints
match(n:node_label)
where all(i in constraints where i.min <= n[i.prop] <= i.max)
return n

Thank you, this works beautifully

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online