# Is there a way to parse country names to Geospatial Coordinates?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-parse-country-names-to-geospatial-coordinates/268716>\
**Category:** Kibana\
**Created:** [March 30, 2021, 3:35am UTC](https://discuss.elastic.co/t/is-there-a-way-to-parse-country-names-to-geospatial-coordinates/268716 "2021-03-30T03:35:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![caitlyn.carlisle](https://avatars.discourse-cdn.com/v4/letter/c/edb3f5/32.png) [@caitlyn.carlisle](https://discuss.elastic.co/u/caitlyn.carlisle)\
**Post date:** [March 30, 2021, 3:35am UTC](https://discuss.elastic.co/t/is-there-a-way-to-parse-country-names-to-geospatial-coordinates/268716/1 "2021-03-30T03:35:44Z")

</div>

I am attempting to create a map using Kibana. I currently only have the country name as one of my data points but was wondering if there was a way to easily convert it to the Geospatial Coordinates? I am using a Logstash pipeline to ingest the data in Elasticsearch from MongoDB. I looked into GeoIP but it doesn't seem to do what I am looking for.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 30, 2021, 3:38am UTC](https://discuss.elastic.co/t/is-there-a-way-to-parse-country-names-to-geospatial-coordinates/268716/2 "2021-03-30T03:38:18Z")

</div>

There's a few external APIs out there that you can use, but I don't know a nicely packaged way to do this. Hopefully someone can comment though cause this is definitely something of interest for me! 🙂

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [March 30, 2021, 4:59am UTC](https://discuss.elastic.co/t/is-there-a-way-to-parse-country-names-to-geospatial-coordinates/268716/3 "2021-03-30T04:59:38Z")

</div>

Hi @caitlyn.carlisle

Curious when you say Geospatial Coordinates do want a point or the outline / boundary of the country?

Also did you know you can do a join in the map itself if you have the country code in one index and then do a "term join" to the country boundaries in another index.

See [here](https://www.elastic.co/guide/en/kibana/current/terms-join.html)

If you did get a geojson of say the centroids of the countries you could use an enrich processor to add the geo data on ingest.

Just a couple thoughts

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [March 30, 2021, 5:09pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-parse-country-names-to-geospatial-coordinates/268716/4 "2021-03-30T17:09:18Z")

</div>

[Lucene Geo-Gazetteer](https://github.com/chrismattmann/lucene-geo-gazetteer) is an interesting project that appears to do this.

[Mordecai](https://github.com/openeventdata/mordecai) may also be of interest to you.

Note, I have not tested either of these projects.

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [March 30, 2021, 6:12pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-parse-country-names-to-geospatial-coordinates/268716/5 "2021-03-30T18:12:23Z")

</div>

But, since you're only using countries, my earlier suggestions might be out of scope for this.

I like @stephenb's idea of using the enrich processor for this. But countries can be referred to by many different names (e.g. Vietnam, Viet Nam, Socialist Republic of Vietnam, ...). The gazetteer data from [Geonames](https://geonames.org) has places names, centroids, and alternative names. Perhaps you can ingest the country names and centroids from geonames into Elasticsearch. I would put the country name and all alternative names into a single keyword field. Then we can use this with an enrich policy to add the locations to your logs at ingest.

I copied and pasted a test from my own Kibana console as an example below.

```auto
PUT geonames-countries

PUT geonames-countries/_mapping
{
  "properties": {
    "name": {
      "type": "keyword"
    },
    "location": {
      "type": "geo_point"
    }
  }
}

PUT geonames-countries/_doc/1
{
  "name": ["Vietnam", "Viet Nam", "Socialist Republic of Vietnam"],
  "location": [108.533936,13.370915]
}

GET geonames-countries/_search
{
  "query": {
    "term": {
      "name": {
        "value": "Viet Nam"
      }
    }
  }
}

PUT _enrich/policy/country_centroids
{
  "match": {
    "indices": "geonames-countries",
    "match_field": "name",
    "enrich_fields": ["location"]
  }
}

POST _enrich/policy/country_centroids/_execute

POST _ingest/pipeline/_simulate?verbose=false
{
  "pipeline": {
    "processors": [
      {
        "enrich": {
          "policy_name": "country_centroids",
          "field": "country_name",
          "target_field": "location"
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "my-logs-index",
      "_type": "_doc",
      "_id": "foo",
      "_source": {
        "country_name": "Viet Nam"
      }
    }
  ]
}

```

---

<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:** [April 27, 2021, 6:12pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-parse-country-names-to-geospatial-coordinates/268716/6 "2021-04-27T18:12:31Z")

</div>

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