byintersection spatial filter not work properly after the elastic search 8 migration and code refactor

This is a regression bug and happened after migrating to elastic version 8 and code refactor: #133

The issue is that new code generates incorrect elastic search query when given the byintersection spatial filter.

E.g. The following spatial filter

{"field":"data.Location","byIntersection":{"polygons":[{"points":[{"latitude":-89.0,"longitude":-179.0},{"latitude":-89.0,"longitude":179.0},{"latitude":89.0,"longitude":179.0},{"latitude":89,"longitude":-179.0},{"latitude":-89.0,"longitude":-179.0}]}]}}

will be translated into the following elastic search query, and cause an elastic exception

GeoShapeQuery: {"data.Location":{"shape":"{geometries=[{coordinates=[[[-179.0, -89.0], [179.0, -89.0], [179.0, 89.0], [-179.0, 89.0], [-179.0, -89.0]]], type=MultiPolygon}], type=GeometryCollection}","relation":"intersects"},"ignore_unmapped":true}

ErrorResponse: {"error":{"type":"x_content_parse_exception","reason":"[1:647] [vector-tile] failed to parse field [query]","caused_by":{"type":"x_content_parse_exception","reason":"[1:647] [bool] failed to parse field [must]","caused_by":{"type":"x_content_parse_exception","reason":"[1:617] [geojson] failed to parse field [geometries]","caused_by":{"type":"x_content_parse_exception","reason":"Failed to build [geojson] after last required field arrived","caused_by":{"type":"exception","reason":"expected a list of points but got a point"}}}},"root_cause":[{"type":"exception","reason":"expected a list of points but got a point"}]},"status":400}

According to the GeoJSON standard that elastic search doc refers to (https://datatracker.ietf.org/doc/html/rfc7946), the correct geojson for the multipolygon should be something as follows.

image

So the above byIntersection spatial filter should be converted into the following to make it work with elastic search

GeoShapeQuery: {"data.Location":{"shape":"{coordinates=[[[[-179.0, -89.0], [179.0, -89.0], [179.0, 89.0], [-179.0, 89.0], [-179.0, -89.0]]]], type=MultiPolygon}","relation":"intersects"},"ignore_unmapped":true}

We don't have the integration test on byIntersection spatial filter, so it didn't catch this regression, we need to add an additional int test case to cover this filter

Edited by Mingyang Zhu