Geo Distance Search on Geo Shape with distance returned

Based on the discussion here 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:

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:

{
  "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.

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

image

What's the mapping?

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

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. 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.

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:

Note that sorting on geo_shape fields is not supported.

1 Like