# Geographic direction correspondence

**URL:** <https://discuss.elastic.co/t/geographic-direction-correspondence/214211>\
**Category:** Elasticsearch\
**Created:** [January 8, 2020, 10:49am UTC](https://discuss.elastic.co/t/geographic-direction-correspondence/214211 "2020-01-08T10:49:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eth3rnit3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eth3rnit3/32/60455_2.png) [@Eth3rnit3](https://discuss.elastic.co/u/Eth3rnit3)\
**Post date:** [January 8, 2020, 10:49am UTC](https://discuss.elastic.co/t/geographic-direction-correspondence/214211/1 "2020-01-08T10:49:08Z")

</div>

Hi, I could use your help writing a query.

I use polygon searching using geo\_polygon and it works very well, however I would like to refine the search results to receive only hits that would be in the same direction as my search.

In a user search, I determine a bearing which is a number between 0 and 360.  
On the Elasticsearch side, I also have a bearing field.

I would like the search to filter the results that would have a bearing of more or less 90° (around a circle so reset to zero if greater than 360).

I hope I've made myself clear, if not, feel free to ask me for more details.

I thank you in advance

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 9, 2020, 3:38pm UTC](https://discuss.elastic.co/t/geographic-direction-correspondence/214211/2 "2020-01-09T15:38:19Z")

</div>

Unless I am fundamentally misunderstand the requirement regarding the bearing, this sounds like a boolean query with two clauses in the `must` part. One for the bearing and one for the geo polygon query.

See [https://www.elastic.co/guide/en/elasticsearch/reference/7.5/query-dsl-bool-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/query-dsl-bool-query.html)

---

<div class="post-metadata">

**Author:** ![Eth3rnit3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eth3rnit3/32/60455_2.png) [@Eth3rnit3](https://discuss.elastic.co/u/Eth3rnit3)\
**Post date:** [January 10, 2020, 2:04pm UTC](https://discuss.elastic.co/t/geographic-direction-correspondence/214211/3 "2020-01-10T14:04:40Z")

</div>

Indeed, I managed to find a solution to my problem by putting a condition, the request must be `should` in the case where `minBearing` and `maxBearing` included 360° and in `must` the opposite case.

```auto
minBearing = bearing - 90°
maxBearing = bearing + 90°

```

Thank you for your response

---

<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:** [February 7, 2020, 2:04pm UTC](https://discuss.elastic.co/t/geographic-direction-correspondence/214211/4 "2020-02-07T14:04:42Z")

</div>

Closed on February 7, 2020, 2:04pm UTC

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