# How to search using geo\_distance and two indices

**URL:** <https://discuss.elastic.co/t/how-to-search-using-geo-distance-and-two-indices/230897>\
**Category:** Elasticsearch\
**Created:** [May 3, 2020, 7:25pm UTC](https://discuss.elastic.co/t/how-to-search-using-geo-distance-and-two-indices/230897 "2020-05-03T19:25:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pierre\_S\_Almeida](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierre_s_almeida/32/49232_2.png) [@Pierre\_S\_Almeida](https://discuss.elastic.co/u/Pierre_S_Almeida)\
**Post date:** [May 3, 2020, 7:25pm UTC](https://discuss.elastic.co/t/how-to-search-using-geo-distance-and-two-indices/230897/1 "2020-05-03T19:25:52Z")

</div>

Hi,

I am trying to make a query on elasticsearch that reproduce the same result of this SQL:

```auto
    select pl.latitude, pl.longitude from places as pl
    where exists (
    select rf.id from references as rf where ST_Distance_Sphere(
            point(pl.longitude, pl.latitude),
            point(rf.longitude, rf.latitude)
        ) < 1000 
    ) 

```

In other words, based on two indices, to find out which place is less than 1000 meters from any reference in set registered.

My indices are:

```auto
GET /places
{
  "places" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "location" : {
          "type" : "geo_point"
        }
      }
    }
}

GET /references
{
"references" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "location" : {
          "type" : "geo_point"
        }
      }
    }
}

```

Is it possible in ES?

---

<div class="post-metadata">

**Author:** ![miked187](https://avatars.discourse-cdn.com/v4/letter/m/3da27b/32.png) [@miked187](https://discuss.elastic.co/u/miked187)\
**Post date:** [May 3, 2020, 9:13pm UTC](https://discuss.elastic.co/t/how-to-search-using-geo-distance-and-two-indices/230897/2 "2020-05-03T21:13:58Z")

</div>

```auto
GET /references, /places
{
...

```

[https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-index.html)

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 4, 2020, 4:13am UTC](https://discuss.elastic.co/t/how-to-search-using-geo-distance-and-two-indices/230897/3 "2020-05-04T04:13:02Z")

</div>

This is a join, which Elasticsearch does not support. It is therefore not possible to do this in a single query. You probably need to break this up into multiple queries in you application or restructure your data somehow.

---

<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:** [June 1, 2020, 4:13am UTC](https://discuss.elastic.co/t/how-to-search-using-geo-distance-and-two-indices/230897/4 "2020-06-01T04:13:05Z")

</div>

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