UVicMartletplace / martletplace

Recreating FB Marketplace for Students - UVic SENG499 Capstone Project
1 stars 0 forks source link

Latitude and Longitude search filtering and sorting broken during pgsync syncing #260

Open GDeane opened 5 days ago

GDeane commented 5 days ago

Describe the bug

I'm running into the problem where elasticsearch requires location fields to be mapped as geo_point with the fields "lat" and "lon" in order to search by location (https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-point.html).

previously, (when using reindexing API) location fields looked like this: "location": { "lat": 45.4215, "lon": -75.6972 },

Now, they look like this after using PGSync: "location": { "latitude": 40.7128, "longitude": -74.006 },

When I search by location, I currently get this error: image.

In short, if location can't be changed to "lat" and "lon" instead of "latitude" and "longitude" using the PGSync schema (or some other method), we won't be able to search within 5 km of or sort by location.

Meanwhile, PGSync has the issue where it does not recognize the LOCATION_TYPE defined in PGSync image

I have not been able to figure out how to resolve this.

Originally posted by @GDeane in https://github.com/UVicMartletplace/martletplace/issues/214#issuecomment-2190722842

To Reproduce

Steps to reproduce the behaviour:

  1. Uncomment the location based filtering and sorting code in the /api/search endpoint in routes.py Image

  2. In terminal in the martletplace directory, run docker-compose down , then docker-compose up --build elasticsearch database pgsync search (this builds a reduced portion of the application)

  3. Once the application has finished building successfully, uncomment this test in test_server.py: Image

  4. In a fresh terminal, run docker exec -it martletplace_search bash

  5. In the resulting bash terminal, run pytest src/test_server.py (this runs the tests)

Expected behaviour

All tests pass without issue

Actual (problematic) behavior

A number of tests fail for this reason: Image

Suggested fix

Figure out a way to modify the pgsync schema.json to apply the following transformation:

In postgres "location": { "latitude": 45.4215, "longitude": -75.6972 },

In elasticsearch "location": { "lat": 40.7128, "lon": -74.006 },

Everything location related should work then.