cancel
Showing results for 
Search instead for 
Did you mean: 

Try to structure and automate a query

rusthinges
Node

I have a table that has columns for person name, their location, day, month and year as well as longitude and latitude of the location which I have imported into Neo4j. I am trying to structure a query that that would identify people that where within 20 km of each other at any day, that can automatically run through all the rows of the tables/nodes. Is there a way of doing this using the spatial function in neo4j, I am stuck and would need some ideas/help.

2 REPLIES 2

mark3
Node Link

Hi,

That's going to be quite a query as you'll have to compare every person's location with every other person's location on the same day (a cartensian product) which can rapidly slow down your query as the number of people increases.

That aside, if you have stored the lat and long data in a geospatial 'point' you can use the 'distance()' funtion to work out the distance between two points in the units the point data is stored in.

Have a look at https://neo4j.com/docs/cypher-manual/current/functions/spatial/

I'm going to think a bit more about the cartesian product part of the problem.

Regards,

Mark

rusthinges
Node

Quick question, I am running a cypher query which continues to crash my machine. and not reaching the stage to produce results. Is there a way I can change and make this query efficient so that I can get some result?

MERGE (c:Collector)<-[:VISITED_BY]-(Site)-[:VISITED_BY]->(c1:Collector)
WITH c, c1, Site
ORDER BY c, Site.year
WITH c, c1, collect(Site)[0].year AS year, count(*) AS collaborations WHERE year>1801
MERGE (c)-[cocollector:CO_COLLECTOR{year:year}]-(c1)
SET cocollector.collaborations = collaborations

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.