Aggregate into "best fit" buckets?

I'm looking for a way to put my data into one of a set of buckets depending on to which of a list of labels is closest to some field in each document. By way of example, say I have a geo-location point in each document and I have a list of the lat/lon points for a set of cities and then I'd like to put my documents into buckets depending on which city is closest.

In my current case the labels on the buckets are geo-locations but I have some other cases where I'd like to group the documents based on which of a set of text values lies closest.

Is there currently any mechanism in Elasticsearch to compute a set of scores for each document against a set of target values and then place the documents into buckets based on which target value gives the highest (or lowest) score? It seems like it would be a generically useful feature for a whole host of purposes; it even lets you compute a round of K-means clustering in a single aggregation query without the data leaving the servers.

Any suggestions for how to do this would be much appreciated.

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