# How to convert lat/lon data coming from MongoDB to geo\_point type?

**URL:** https://discuss.elastic.co/t/how-to-convert-lat-lon-data-coming-from-mongodb-to-geo-point-type/165980
**Category:** Logstash
**Created:** [January 28, 2019, 10:34am UTC](https://discuss.elastic.co/t/how-to-convert-lat-lon-data-coming-from-mongodb-to-geo-point-type/165980 "2019-01-28T10:34:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![topgun743](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/topgun743/32/39867_2.png) [@topgun743](https://discuss.elastic.co/u/topgun743)
#### Post date: [January 28, 2019, 10:34am UTC](https://discuss.elastic.co/t/how-to-convert-lat-lon-data-coming-from-mongodb-to-geo-point-type/165980/1 "2019-01-28T10:34:24Z")

</div>

I am trying to index a collection to Elasticsearch from MongoDB.

In MongoDB a document contains a `Position` field which has in turn `lat` and `lon` (float) fields that describe the location of any vehicle.  
I want these points to be converted to `geo_point` so that later on we get better and faster aggregation stuff. I am creating a new field named `location` via my input config file.

Problem is, new field `location` is created but it is not of `geo_point` type.  
I have read numerous forums including stackoverflow and there people are suggesting to first create mapping for geo point before the index creation on Elasticsearch via PUT API.

But I want to know if there is any other way via .conf input file, to create _geo\_point_ without creating their mapping first in Elasticsearch. Is it possible?

Here is my sample document in MongoDB:

```
{
    "_id" : ObjectId("59a41f63dba6488b3326834f"),
    "MediaID" : "DVR_Backseat_1_362019210",
    "IsRestrictedView" : true,
    "Position" : {
        "lon" : 67.0486,
        "lat" : 24.8589
     }
}

```

Here is my .conf input file:

```
input {
	mongodb {
		uri => 'mongodb://localhost/TestDB'
		placeholder_db_dir => 'E:/logstash-mongodb/'
		placeholder_db_name => 'logstash_sqlite.db'
		collection => 'MediaSummary'
		batch_size => 5000
		generateId => false
		parse_method => "simple"
    }
}

filter {
	mutate {
        rename => { "_id" => "mongo_id" }
	}
	grok {
		match => { "Position" => "^?\"lon\"=>%{NUMBER:lon},\s\"lat\"=>%{NUMBER:lat}" }
	}
	date {
		match => ["timestamp", "YYYY-MM-dd HH:mm:ss ZZZ"]
    }
	mutate {
		convert => {"lat" => "float"}
		convert => {"lon" => "float"}
	}
	mutate {
		add_field => { "location" => "%{[lat]}, %{[lon]}" }
	}
	mutate {
		convert => {"IsRestrictedView" => "boolean"}
	}
}

output {
	stdout {
		codec => rubydebug
	}
	elasticsearch {
		hosts => ["127.0.0.1:9200"]
		index => "mediasummary"
		doc_as_upsert => true
		document_id => "%{mongo_id}"
	}
}

```

Please note that `Position` field shows up as following in stdout:

`"Position" => "{\"lon\"=>67.0487, \"lat\"=>24.859}"`

Also note that I have used `parse_method => "simple"`. This is because otherwise boolean variables are not converted correctly.

So what should I do to get `location` field as `geo_point` type?

---

<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: [January 28, 2019, 2:02pm UTC](https://discuss.elastic.co/t/how-to-convert-lat-lon-data-coming-from-mongodb-to-geo-point-type/165980/2 "2019-01-28T14:02:26Z")

</div>

> [@topgun743](#):
>
> But I want to know if there is any other way via .conf input file, to create _geo\_point_ without creating their mapping first in Elasticsearch. Is it possible?

If your field is called geoip then the default mapping will make that a geo\_point. For _any_ other field name you need a mapping. [This](https://discuss.elastic.co/t/location-dosent-convert-to-geo-point/131199/4) thread might help.

---

<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: [February 25, 2019, 2:02pm UTC](https://discuss.elastic.co/t/how-to-convert-lat-lon-data-coming-from-mongodb-to-geo-point-type/165980/3 "2019-02-25T14:02:26Z")

</div>

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