Elasticsearch - nested field with geo_point type returns unsupported symbol in search

Mapping for the index:

PUT /my_locations
{
  "mappings": {
    "properties": {
      "pin": {
        "type":"nested", 
        "properties": {
          "location": {
            "type": "geo_point"
          }
        }
      }
    }
  }
}

Search query:

GET /my_locations/_search
{
  "sort": [
    "_score",
    {
      "_geo_distance": {
        "nested_path": "pin",
        "query": {
          "pin.location": {
            "lat":41.12,
            "lon":-71.34
          },
          "unit": "mi",
          "order": "asc"
        }
      }
    }
  ]
}

Response:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "parse_exception",
        "reason" : "unsupported symbol [i] in geohash [pin]"
      }
    ],
    "type" : "parse_exception",
    "reason" : "unsupported symbol [i] in geohash [pin]",
    "caused_by" : {
      "type" : "illegal_argument_exception",
      "reason" : "unsupported symbol [i] in geohash [pin]"
    }
  },
  "status" : 400
}

Elasticsearch and Kibana version: 8.1.3

Can you please suggest a solution for this error?

Hi!!
What the reason for type to be nested?

This works:

GET /my_locations/_search
{
  "sort": [
    "_score",
    {
      "_geo_distance": {
        "pin.location": {
          "lat": 40,
          "lon": -70
        },
        "unit": "mi",
        "order": "asc"
      }
    }
  ]
}

I performed the example in this doc and get successful.

Wild guess from a quick read: Is is possible, that you need to use a geo distance query within the nested sort? See Sort search results | Elasticsearch Guide [8.2] | Elastic where a filter is used as an example.

Hi @RabBit_BR

Thank you for your response.

Basically, I have multiple elements inside pin (XML data) that I convert to JSON and index in Elasticsearch. For example,

<root>
<pin>
<location>621215</location>
</pin>
<pin>
<location>621214</location>
</pin>
</root>

So, I have chosen the type of pin nested. Your query for my index reports error in my environment. Please find the error below.

{
  "error" : {
    "root_cause" : [
      {
        "type" : "query_shard_exception",
        "reason" : "it is mandatory to set the [nested] context on the nested sort field: [pin.location].",
        "index_uuid" : "-2-ExiOnRyy6ygTPJCIRrQ",
        "index" : "my_locations"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "my_locations",
        "node" : "XDpHvG5tSEuy-83Iwfu4EA",
        "reason" : {
          "type" : "query_shard_exception",
          "reason" : "it is mandatory to set the [nested] context on the nested sort field: [pin.location].",
          "index_uuid" : "-2-ExiOnRyy6ygTPJCIRrQ",
          "index" : "my_locations"
        }
      }
    ]
  },
  "status" : 400
}

Please let me know if you need some more details.

Hi @spinscale

Thank you for your response. Geo distance seems not working within the nested sort.

Would you please give some samples?

When you convert the data are you using a geoIP processor?

@RabBit_BR - having a mapping file contains postal code to lat lon values.

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