# Mapping Geo-location From Database

**URL:** <https://discuss.elastic.co/t/mapping-geo-location-from-database/42553>\
**Category:** Elasticsearch\
**Created:** [February 24, 2016, 5:43am UTC](https://discuss.elastic.co/t/mapping-geo-location-from-database/42553 "2016-02-24T05:43:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Croos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/croos/32/29489_2.png) [@Croos](https://discuss.elastic.co/u/Croos)\
**Post date:** [February 24, 2016, 5:43am UTC](https://discuss.elastic.co/t/mapping-geo-location-from-database/42553/1 "2016-02-24T05:43:11Z")

</div>

I have a table and want to visualize on kibana.  
`lead_id | longitude | latitude`  
When I import it to elastic search using logstash, How can I map it on elasticsearch?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 24, 2016, 6:45am UTC](https://discuss.elastic.co/t/mapping-geo-location-from-database/42553/2 "2016-02-24T06:45:03Z")

</div>

Two things:

- Store the longitude and latitude values in a field whose format can be parsed as a geo\_point field (the ES documentation has details).
- Make sure the index maps that particular field as a geo\_point field.

---

<div class="post-metadata">

**Author:** ![Croos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/croos/32/29489_2.png) [@Croos](https://discuss.elastic.co/u/Croos)\
**Post date:** [February 25, 2016, 1:32pm UTC](https://discuss.elastic.co/t/mapping-geo-location-from-database/42553/3 "2016-02-25T13:32:34Z")

</div>

My config file:

```
filter {
  csv{
    columns => ["lead_id","first_name","latitude","longitude"]
    separator => ","
  }
}

output {
  stdout { 
    codec => rubydebug 
  }
  
  elasticsearch {
    hosts => ["localhost:9200"]
    index=>"croos_test"
    document_id => "%{lead_id}"       
    location=>["%{latitude}", "%{longitude}"]
  }
}

```

My mapping:

```
"mappings": {
      "geo_test": {
        "_timestamp": {
          "enabled": true
        },
        "properties": {
          "first_name": {
            "type": "string",
            "analyzer": "standard"
          },
          "location": {
            "type": "geo_point"
          }
        }
      }
    }

```

How to make index maps that particular field as a geo\_point field?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 25, 2016, 3:22pm UTC](https://discuss.elastic.co/t/mapping-geo-location-from-database/42553/4 "2016-02-25T15:22:56Z")

</div>

```
location=>["%{latitude}", "%{longitude}"]

```

No, this doesn't work. Use the mutate filter and its `add_field` option to create new fields. To create an array field I believe the following works:

```auto
mutate {
  add_field => ["location", "%{latitude}"]
  add_field => ["location", "%{longitude}"]
}

```

---

<div class="post-metadata">

**Author:** ![Croos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/croos/32/29489_2.png) [@Croos](https://discuss.elastic.co/u/Croos)\
**Post date:** [February 29, 2016, 9:53am UTC](https://discuss.elastic.co/t/mapping-geo-location-from-database/42553/5 "2016-02-29T09:53:37Z")

</div>

Thanks a lot Magnus.

```
{
       "message" => "16798207,Yonago,35.433,133.333\r",
      "@version" => "1",
    "@timestamp" => "2016-02-29T09:30:26.379Z",
          "path" => "country1.csv",
          "host" => "Lenovo-PC",
          "type" => "data",
            "id" => "16798207",
    "first_name" => "Croos",
      "location" => {
        "lat" => "35.433",
        "lon" => "133.333"
    }
}
{
       "message" => "16798463,Izumo,35.367,132.767\r",
      "@version" => "1",
    "@timestamp" => "2016-02-29T09:30:26.379Z",
          "path" => "country1.csv",
          "host" => "Lenovo-PC",
          "type" => "data",
            "id" => "16798463",
    "first_name" => "Vinith",
      "location" => {
        "lat" => "35.367",
        "lon" => "132.767"
    }
}

```

Now the logstash executed successfully. Now my problem is visualizing the same on kibana. For that, I start another [thread](https://discuss.elastic.co/t/visualizing-geo-points-on-kibana/42985).

---

<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:** [July 5, 2017, 11:12pm UTC](https://discuss.elastic.co/t/mapping-geo-location-from-database/42553/6 "2017-07-05T23:12:53Z")

</div>


