Neo4j where predicates on multiple attributes

Viewed 37

In Neo4j, for the where predicate, can we have constraints on more than one property? For example, suppose that we have a list of pairs: L = [(23, 'San Diego'), (25, 'Palo Alto'), (21, 'Seattle'), ....], then does Cypher support something similar to the following:

Match (a) where (a.age, a.city) in L return a

The age and city combinations need to be in the L list

1 Answers

Neo4j does not accept tuples but map of key, value pairs (or dictionary).

However, this query will be close to what you have described.

WITH [{age:23, city:'San Diego'}, {age:25, city:'Palo Alto'}, {age:21, city:'Seattle'}] as L
MATCH (p:Person) WHERE {age: p.age, city: p.city} in L
RETURN p 

Sample result:
╒═══════════════════════════════════════════╕
│"p"                                        │
╞═══════════════════════════════════════════╡
│{"name":"Andy","city":"San Diego","age":23}│
└───────────────────────────────────────────┘

See below:

https://neo4j.com/docs/cypher-manual/current/syntax/values/#composite-types
Related