# How to make map clustering through elastic search more flexible?

**URL:** <https://discuss.elastic.co/t/how-to-make-map-clustering-through-elastic-search-more-flexible/342266>\
**Category:** Elasticsearch\
**Created:** [September 4, 2023, 12:29pm UTC](https://discuss.elastic.co/t/how-to-make-map-clustering-through-elastic-search-more-flexible/342266 "2023-09-04T12:29:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladislav\_Kochurko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vladislav_kochurko/32/97270_2.png) [@Vladislav\_Kochurko](https://discuss.elastic.co/u/Vladislav_Kochurko)\
**Post date:** [September 4, 2023, 12:29pm UTC](https://discuss.elastic.co/t/how-to-make-map-clustering-through-elastic-search-more-flexible/342266/1 "2023-09-04T12:29:36Z")

</div>

I am developing an interactive map and my technology stack includes NodeJS, Angular, MapBox, and **Elasticsearch**. My application is a complex data aggregator, and I am trying to cluster my data on the map **using Elasticsearch**.

To understand my problem, let me briefly describe the situation. In Elasticsearch, users are stored as documents, and each user has a location field, which is a `nested` type (meaning that a user can have multiple locations).

On the map, I want to display all user locations along with the number of users in each location. For example, if a user has locations in both Brazil and Italy, their `doc_count` should be included in both Brazil and Italy.

Here is where the clustering problem arises. To maintain the correct `doc_count` for each location, I cannot use any client-side clustering libraries (such as SuperCluster), as they would not be able to accurately calculate the `doc_count` if a person has multiple locations. For example, if a person has locations in both Switzerland and France, and the map is zoomed out, these two countries would merge into one cluster, which would not have the correct `doc_count` value.

Therefore, I can only use the capabilities of Elasticsearch itself. My choice was to use the `geo_tile` aggregation with a nested `geo_centroid` aggregation, which solved the `doc_count` problem and always showed the correct values. However, because `geo_tile` is not a flexible tool, points on the map became too close to each other (for example, points that exist on the boundary of two tiles).

I started looking for a solution that would allow for more flexible clustering without being tied to tiles or a grid. I found a plugin ([GitHub - opendatasoft/elasticsearch-aggregation-geoclustering: An Elasticsearch plugin to aggregate Geo Points in clusters.](https://github.com/opendatasoft/elasticsearch-aggregation-geoclustering)) that did exactly what I needed (especially the ability to specify a radius), but it hasn't been updated in a long time and isn't officially supported. This would be a big bottleneck if I installed it on my project.

Can anyone recommend a ready-made solution to my problem? Perhaps a supported plugin or a solution using the already established tools in Elasticsearch?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 2, 2023, 12:29pm UTC](https://discuss.elastic.co/t/how-to-make-map-clustering-through-elastic-search-more-flexible/342266/2 "2023-10-02T12:29:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
