# How to convert latitude and longitude in logstash and store in elasticserach in a proper format

**URL:** https://discuss.elastic.co/t/how-to-convert-latitude-and-longitude-in-logstash-and-store-in-elasticserach-in-a-proper-format/320116
**Category:** Logstash
**Created:** [November 30, 2022, 7:34am UTC](https://discuss.elastic.co/t/how-to-convert-latitude-and-longitude-in-logstash-and-store-in-elasticserach-in-a-proper-format/320116 "2022-11-30T07:34:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Dhanushka\_Samarasing](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dhanushka_samarasing/32/112421_2.png) [@Dhanushka\_Samarasing](https://discuss.elastic.co/u/Dhanushka_Samarasing)
#### Post date: [November 30, 2022, 7:34am UTC](https://discuss.elastic.co/t/how-to-convert-latitude-and-longitude-in-logstash-and-store-in-elasticserach-in-a-proper-format/320116/1 "2022-11-30T07:34:29Z")

</div>

I have latitude and longitude data in a Postgresql DB, now I need to move those data to Elasticsearch through Logstash pipeline. I have tried different methods but non of them did not work so far.  
This is the sample record in Postgresql  
 ![pg](https://us1.discourse-cdn.com/elastic/original/3X/b/e/beae5d28afcc6e4da6ab8ca00794d33828fbf340.png)

I was trying to migrate those data from pg to elasticsearch using below logstash pipline

```auto
input {
    jdbc {
        type => "dvf"
        jdbc_connection_string => "jdbc:postgresql://<IP>:<Port>/<db>"
        jdbc_user => "<user-name>"
        jdbc_password => "<password>"
        jdbc_driver_library => "/usr/share/logstash/postgresql-42.4.0.jar"
        jdbc_driver_class => "org.postgresql.Driver"
        statement => "SELECT * FROM public.dvf"
        jdbc_fetch_size => 10
        jdbc_paging_enabled => true
    }
}

filter {
    mutate {
        convert => {
            "adresse_numero" => "string"
            "adresse_code_voie" => "string"
            "code_postal" => "string"
            "code_departement" => "string"
            "id_parcelle" => "string"
            "nom_commune" => "string"
            "latitude" => "string"
            "longitude" => "string"
        }
    }
}

output {
    #stdout { codec => rubydebug}
    if [type] == "dvf" {
        elasticsearch {
            index => "search-dvf-data-%{+yyyy.MM.dd}"
            hosts => ["https://es-host"]
            ssl => true
            ssl_certificate_verification => true
            user => '<es-use>'
            password => '<es-password>'
        }
    }
}

```

The issue is that I do not get the proper data in Elasticsearch.  
here is what I get in ES,  
 ![es](https://us1.discourse-cdn.com/elastic/original/3X/e/1/e12f7ab3b2e1cb7f5408498a79e8207db4ebe152.png)

In the above logstash pipeline filter I used to convert the `latitude` and `longitude` to string.  
Hoping to fix this issue, I was trying to send the data type as float. but the result is the same.

How to convert geo coordinates from logstash filtering and properly store in Elasticsearch index?  
Any help would be appreciated.

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [November 30, 2022, 5:45pm UTC](https://discuss.elastic.co/t/how-to-convert-latitude-and-longitude-in-logstash-and-store-in-elasticserach-in-a-proper-format/320116/2 "2022-11-30T17:45:04Z")

</div>

You will need a [template](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html) to tell elasticsearch that those fields a geo\_points. There is an example [here](https://github.com/logstash-plugins/logstash-output-elasticsearch/blob/main/lib/logstash/outputs/elasticsearch/templates/ecs-disabled/elasticsearch-7x.json) of a template that does that.

---

<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: [December 28, 2022, 5:45pm UTC](https://discuss.elastic.co/t/how-to-convert-latitude-and-longitude-in-logstash-and-store-in-elasticserach-in-a-proper-format/320116/3 "2022-12-28T17:45:45Z")

</div>

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