I have osm data and trying to find nearest points for my given input of start and end lat & long, in this i am applying filter of tags, and tags are available in relationship CONNECTED_TO, now after getting my nearest points in db i am giving it to another query to get shortest route between them. Now this whole process is taking too much time like in minutes, i am posting both the queries below please suggest me like what to change in queries for reducing my result timing.
shortest route
`WITH point({latitude: ${node.latitude}, longitude: ${node.longitude}}) AS givenPoint
MATCH (n:Node)
WITH n, givenPoint, point.distance(givenPoint, point({latitude: n.latitude, longitude: n.longitude})) AS distanceToNode
WHERE distanceToNode <= 500
WITH n, distanceToNode
MATCH (w:Way)
WHERE n.id IN w.nodes AND (w.tags =~ '.*${filters}.*')
RETURN w, n, distanceToNode
ORDER BY distanceToNode ASC
LIMIT 1
nearest point
`WITH point({latitude: ${node.latitude}, longitude: ${node.longitude}}) AS givenPoint
MATCH (n:Node)
WITH n, givenPoint, point.distance(givenPoint, point({latitude: n.latitude, longitude: n.longitude})) AS distanceToNode
WHERE distanceToNode <= 500
WITH n, distanceToNode
MATCH (w:Way)
WHERE n.id IN w.nodes AND (w.tags =~ '.*${filters}.*')
RETURN w, n, distanceToNode
ORDER BY distanceToNode ASC
LIMIT 1
`