Sorting by geolocation outside of mapping constraints

I have an elasticsearch db of postcode data.

for fast searching I have used both _type by country and also added routing
so I can search a subset of data within 1 shard, rather than all shards.

the mapping looks like this:

The important part of this mapping is "location" which I am setting to
"geo_point" for each country mapping

When querying, I am using both _type and routing to search with



This gives me a much smaller subset of data on which to sort by distance

query looks like this:

Note that in the sort section it is in the format of the location is
"country.locaton" keeping with the mapping set up earlier.

But what happens if I need to search over the whole DB and not just 1
country? how do I sort by location when the country is unknown and each doc
has a _type = countrycode?

In the sort section:

"sort": [{
"_geo_distance": {
"au.location": [146.35,
"order": "asc",
"unit": "km"

What should the "au.location" look like when I do not know it is "au"?

Is it possible to search the results and sort them by location in this
case? or is there a way to do it better that would allow the results to be
sorted by location regardless of knowing the mapping "name"?

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit