# 2 way search by query and incoming docs

**URL:** <https://discuss.elastic.co/t/2-way-search-by-query-and-incoming-docs/363170>\
**Category:** Elasticsearch\
**Created:** [July 15, 2024, 3:54pm UTC](https://discuss.elastic.co/t/2-way-search-by-query-and-incoming-docs/363170 "2024-07-15T15:54:41Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![elsaticnoob](https://avatars.discourse-cdn.com/v4/letter/e/c57346/32.png) [@elsaticnoob](https://discuss.elastic.co/u/elsaticnoob)\
**Post date:** [July 17, 2024, 11:34am UTC](https://discuss.elastic.co/t/2-way-search-by-query-and-incoming-docs/363170/7 "2024-07-17T11:34:25Z")

</div>

hi David and Kathleen, apologies again for breaking the guidelines. will keep in mind for the future.

regarding the Boolean queries, are you suggesting something like this:

```auto
"must": {
    "script": {
      "script": {
          "source": """
            double distance = doc['location'].arcDistance(params.lat, params.lon) / 1000;
          
            boolean isWithinDistance = distance <= doc['searchRadius'].value;
            boolean isWithinAge = params.age >= doc['minAge'].value && params.age <= doc['maxAge'].value;
            
            return isWithinDistance && isWithinAge;
          """,
          "params": {
            "lat":51.545874,
            "lon": 0.048306,
            "age": 28
          }
      }
    }
}

```

the above works but my concern is around efficiency, would you say this is the most efficient way of filtering based on the incoming parameters? is there any other feature that I am not aware of / should look into? thank you so much for your help!

---

_[View the full topic](https://discuss.elastic.co/t/2-way-search-by-query-and-incoming-docs/363170)._
