# Expand search if results are less than a Limit

**URL:** <https://discuss.elastic.co/t/expand-search-if-results-are-less-than-a-limit/27954>\
**Category:** Elasticsearch\
**Created:** [August 24, 2015, 1:55pm UTC](https://discuss.elastic.co/t/expand-search-if-results-are-less-than-a-limit/27954 "2015-08-24T13:55:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stoppy](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@stoppy](https://discuss.elastic.co/u/stoppy)\
**Post date:** [August 24, 2015, 1:55pm UTC](https://discuss.elastic.co/t/expand-search-if-results-are-less-than-a-limit/27954/1 "2015-08-24T13:55:53Z")

</div>

Hi, I would look inside a bounding box and I read how to do it. But I would like to expand this search to a certain range if the hits are less than N.

So: look inside the bounding box of NY, if results are less than 10 look for objects in a range of 100Kms

Is it possible?

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [August 24, 2015, 4:00pm UTC](https://discuss.elastic.co/t/expand-search-if-results-are-less-than-a-limit/27954/2 "2015-08-24T16:00:18Z")

</div>

I don't think it's possible inside of one DSL call. You can handle this logic on the client side via two DSL queries.

---

<div class="post-metadata">

**Author:** ![DracoBlue](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dracoblue/32/4362_2.png) [@DracoBlue](https://discuss.elastic.co/u/DracoBlue)\
**Post date:** [August 24, 2015, 4:31pm UTC](https://discuss.elastic.co/t/expand-search-if-results-are-less-than-a-limit/27954/3 "2015-08-24T16:31:21Z")

</div>

I would use  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)  
to combine a query for the small bounding box (with big score boost) and a  
query for the bigger bounding box (with lower score boost).

Then Elasticsearch will boost the entries which are in the smaller bounding  
box x-times higher then the ones in the bigger bounding box. So you end up  
having the elements in the small bounding box as first results and the  
other elements will appear afterwards in the result list.

---

<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 5, 2017, 11:54pm UTC](https://discuss.elastic.co/t/expand-search-if-results-are-less-than-a-limit/27954/4 "2017-07-05T23:54:09Z")

</div>


