Deprecated FILTER and EXTRACT

I am following examples of the book "Neo4j Graph Data Modeling" to learn Cypher. Unfortunately, some of the codes have been deprecated in newer versions of Cypher. Could some one teach me how to change the following old codes to the current version:

MATCH path = (london:City{name:'London'})-[:HAS_FLIGHT|FLYING_TO*0..6]->(melbourne:City{name:'Melbourne'})
WITH
FILTER(f in nodes(path) WHERE "Flight" IN labels(f)) as flights,
FILTER(city in nodes(path) WHERE "City" IN labels(city)) as cities
RETURN
EXTRACT(city IN cities| city.name) as city,
EXTRACT (flight IN flights| flight.code) as code,
EXTRACT (flight IN flights| flight.carrier) as carrier,
EXTRACT (flight IN flights| flight.departure) as departure,
EXTRACT (flight IN flights| flight.arrival) as arrival,
EXTRACT (flight IN flights| flight.duration) as duration,
EXTRACT (flight IN flights| flight.source_airport_code) as from_airport,
EXTRACT (flight IN flights| flight.destination_airport_code) as to_airport

In fact extract/filter were introduced before the list comprehension which allows you both mapping and filtering. See https://neo4j.com/docs/cypher-manual/current/syntax/lists/#cypher-list-comprehension for details.

Thank you for pointing me to the right direction. I have revised the query to the following and it works.

MATCH path = (london:City{name:'London'})-[:HAS_FLIGHT|FLYING_TO*0..6]->(melbourne:City{name:'Melbourne'})
with
[node in nodes(path) WHERE "City" IN labels(node) | node] as cities,
[node in nodes(path) WHERE "Flight" IN labels(node) | node] as flights
RETURN
[city IN cities | city.name] AS city,
[flight IN flights | flight.code] AS code,
[flight IN flights | flight.carrier] AS carrier,
[flight IN flights | flight.departure] AS departure,
[flight IN flights | flight.arrival] AS arrival,
[flight IN flights | flight.duration] AS duration,
[flight IN flights | flight.source_airport_code] AS from_airport,
[flight IN flights | flight.destination_airport_code] AS to_airport

1 Like