Vik Semenov
Vik Semenov

Reputation: 11

Having issues searching polygons that intersect with other polygons with elasticsearch

In our app, ES holds objects with areas field, where areas field in a type of MultiPyligon. (basically, it's an array of polygons).

Now, we need to search for all the objects in which one of their polygons in at least partially falls within a given polygon (in our case it is the current viewport of the map).

The current query that we are experimenting with is the following:

 $params = [
            'index' => self::CrimeIndex,
            'body' => [
                'size' => 10000,
                'query' => [
                    'bool' => [
                        'filter' => [
                            'geo_bounding_box' => [
                                'areas' => [
                                    "top_left" => [
                                        "lat" => $neLat,
                                        "lon" => $neLng
                                    ],
                                    "bottom_right" => [
                                        "lat" => $swLat,
                                        "lon" => $swLng
                                    ]
                                ],
                            ]
                        ]
                    ]
                ]
            ],
];

The problem is that this query gets all the polygons that touch the edges of the bounding box. (see picture). How can we get all the polygons that are at least partially within the bounding box?

enter image description here

Upvotes: 1

Views: 125

Answers (0)

Related Questions