# Geo Distance Search on Geo Shape with distance returned

**URL:** https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212
**Category:** Elasticsearch
**Created:** [October 15, 2020, 2:16pm UTC](https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212 "2020-10-15T14:16:52Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![DavidBokor](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@DavidBokor](https://discuss.elastic.co/u/DavidBokor)
#### Post date: [October 15, 2020, 2:16pm UTC](https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212/1 "2020-10-15T14:16:52Z")

</div>

Based on the discussion [here](https://github.com/elastic/elasticsearch/pull/53466) it looks like searching by distance on a geo shape field is supported as of v7.7.0. I'm using 7.9 and getting an error.

I have two indices, one points and one polygons. I have no problem doing a geo\_distance search on the point index and returning records in sorted order, with the distance calculated.

However, when I try it against my polygon table, I get an error.

Here's the search:

```auto
GET /polygons/_search
{
  "size": 10,
  "query": {
    "geo_distance": {
      "geometry": [
        -80.08191,
        26.29242
      ],
      "distance": 30.48,
      "distance_type": "arc"
    }
  },
  "sort": [
    {
      "_geo_distance": {
        "geometry": [
          {
            "lat": 26.29242,
            "lon": -80.08191
          }
        ],
        "unit": "m",
        "distance_type": "arc",
        "order": "asc"
      }
    }
  ]
}

```

But I get the following error:

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "query_shard_exception",
        "reason" : "field [geometry] is not a **geo_point** field",
        "index_uuid" : "CoVqpfoARqmI-75mrw0Mew",
        "index" : "polygons"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "polygons",
        "node" : "y4igoHidTPC3kB6w6JIagw",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "field [geometry] is not a **geo_point** field",
          "index_uuid" : "CoVqpfoARqmI-75mrw0Mew",
          "index" : "polygons"
        }
      }
    ]
  },
  "status" : 400
}

```

I get the same error if I remove the sort portion of the search.

---

<div class="post-metadata">

### Author: ![DavidBokor](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@DavidBokor](https://discuss.elastic.co/u/DavidBokor)
#### Post date: [October 15, 2020, 2:18pm UTC](https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212/2 "2020-10-15T14:18:31Z")

</div>

Additionally, here is a shot of what a typical geometry in the index looks like:

![image](https://us1.discourse-cdn.com/elastic/original/3X/6/b/6b486527259596675aa8d96f62fca5a532735663.png)

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 15, 2020, 3:00pm UTC](https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212/3 "2020-10-15T15:00:13Z")

</div>

What's the mapping?

---

<div class="post-metadata">

### Author: ![DavidBokor](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@DavidBokor](https://discuss.elastic.co/u/DavidBokor)
#### Post date: [October 15, 2020, 4:55pm UTC](https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212/4 "2020-10-15T16:55:31Z")

</div>

```auto
"geometry": {
          "type": "geo_shape"
        },

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 15, 2020, 7:36pm UTC](https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212/5 "2020-10-15T19:36:20Z")

</div>

Is that the real mapping or what you think it is. How did you get it?

Anyway

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

### Author: ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)
#### Post date: [October 16, 2020, 6:21am UTC](https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212/6 "2020-10-16T06:21:26Z")

</div>

Hi,

I think there is a misunderstanding about the capabilities added in the GitHub issue mentioned above. The only way currently to query a `geo_shape field` is using a `geo_shape query`. In that issue it was added support to use a `Circle` geometry in the query, which is equivalent to a distance query.

We have an issue to enable `geo_distance query` on `geo_shape` fields but it has not yet been implemented:

> <https://github.com/elastic/elasticsearch/issues/54628>
>
> Following the development in #48928, we should enable geo\_distance and geo\_bounding\_box queries over geo\_shape field type.

Note that sorting on geo\_shape fields is not supported.

---

<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: [November 13, 2020, 6:21am UTC](https://discuss.elastic.co/t/geo-distance-search-on-geo-shape-with-distance-returned/252212/7 "2020-11-13T06:21:27Z")

</div>

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