# Help with custom query for geography and density

**URL:** <https://discuss.elastic.co/t/help-with-custom-query-for-geography-and-density/19511>\
**Category:** Elasticsearch\
**Created:** [August 28, 2014, 3:14pm UTC](https://discuss.elastic.co/t/help-with-custom-query-for-geography-and-density/19511 "2014-08-28T15:14:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_R](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@John\_R](https://discuss.elastic.co/u/John_R)\
**Post date:** [August 28, 2014, 3:14pm UTC](https://discuss.elastic.co/t/help-with-custom-query-for-geography-and-density/19511/1 "2014-08-28T15:14:17Z")

</div>

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.

Thanks,  
John

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/71f88f4b-28d8-440d-b36b-8b4ef1238d1b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/71f88f4b-28d8-440d-b36b-8b4ef1238d1b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [July 6, 2017, 1:05am UTC](https://discuss.elastic.co/t/help-with-custom-query-for-geography-and-density/19511/2 "2017-07-06T01:05:48Z")

</div>

Closed on July 6, 2017, 1:05am UTC


