Help with custom query for geography and density

Hope someone can point me in the right direction. I am trying to create a
custom score function that combines geographic distance + density.

For example, in a certain geographic bounding box, I have a list of popular
tourist attractions. Users have marked certain tourist attractions as
their favorite. When a user searches, I would like to show tourist
attractions sorted by distance from the center of the bounding box as well
as by the popularity of the tourist attraction in that bounding box. So if
a user searches for "ice skating," I would like to show the top 10 ice
skating rinks in the bounding box sorted by popularity of that rink. The
result is that the user would see that "X% of users prefer this ice rink
within your area." and results would be sorted accordingly.

I've found in the elastic search docs the ability to perform geographic
searches, but I'm not sure how to incorporate popularity. If popularity
was purely global, I could just order by it, but since the popularity is a
function of the bounding box, it becomes much more complex.

Is there a way to create a custom function that looks at all results in a
bounding box and orders them based on how many gps points each of those
results has in the bounding box?

Hope this is clear. Thanks for the help.


You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit