# Problem to parse geo\_shape from .csv trough logstash

**URL:** https://discuss.elastic.co/t/problem-to-parse-geo-shape-from-csv-trough-logstash/183780
**Category:** Logstash
**Created:** [May 31, 2019, 6:14pm UTC](https://discuss.elastic.co/t/problem-to-parse-geo-shape-from-csv-trough-logstash/183780 "2019-05-31T18:14:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![grainsngrubble](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grainsngrubble/32/47260_2.png) [@grainsngrubble](https://discuss.elastic.co/u/grainsngrubble)
#### Post date: [May 31, 2019, 6:14pm UTC](https://discuss.elastic.co/t/problem-to-parse-geo-shape-from-csv-trough-logstash/183780/1 "2019-05-31T18:14:13Z")

</div>

Hi! I´m trying to ingest a .csv with geo\_shapes as linestrings. Though I keep getting parse exceptions. Have tries to search and to read the documentation, but no progress so I put my faith in you now 👨‍💻👩‍💻

Even though I occasionally succeed to transfer the data to Elasticsearch with Logstash, Kibana won't recognize it as a geo\_shape... any suggestions?

Geo\_shape in input.csv below: [[lon, lat],[lon, lat]]

> [[-74.0446, 40.6899],[-74.0416, 40.6996]]

Logstash.conf

```
input {
	file { path => ["D:/input.csv"]
			  start_position => beginning
			  sincedb_path => "D:/Logstash/logs/last_value_csv.log"		
	}
}
filter {
	csv { separator => ","
		     columns => ["lineprojection"]
		     convert => { "[lineprojection]" => "float" }
	}
	mutate { remove_field => ["message"]
        }	
}
output {
    elasticsearch {
              hosts => "localhost:9200"
              action => "index"
              manage_template => true
              document_id => "%{timestamp}"
              index => "lines"
              template => "D:/template.json"
              template_name => "template"
    }
    stdout { codec => rubydebug 
    }
}

```

Template

```
{
  "order": 0,
  "index_patterns": ["lines*"],
    "settings": {
      "index" : {
        "lifecycle" : {
          "name" : "lines-policy",
          "rollover_alias" : "lines"
        },
        "number_of_shards" : "1",
        "number_of_replicas" : "0"
        }
      },
      "mappings": {
          "properties": {
            "lineprojection": {
              "type": "geo_shape"
            }
       }
    }
}

```

---

<div class="post-metadata">

### Author: ![grainsngrubble](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grainsngrubble/32/47260_2.png) [@grainsngrubble](https://discuss.elastic.co/u/grainsngrubble)
#### Post date: [June 8, 2019, 10:34am UTC](https://discuss.elastic.co/t/problem-to-parse-geo-shape-from-csv-trough-logstash/183780/2 "2019-06-08T10:34:38Z")

</div>

I found a solution myself with a lot of help from this post [by Badger](https://discuss.elastic.co/t/geo-shape-geo-link-problems-with-coordinates/179924/5) and thought I share it if others encounter the same issue.

First, the coordinates should not be arranged in an array in the inout.csv file. Of course you can split the array etc in logstash. But for convenience I arranged my coordinates as below:

`-74.0446, 40.6899,-74.0416, 40.6996`

My logstash.conf for converting the coordinates into a geo\_point location and a linestring geo\_shape. I have excluded the part not relevant for the geo operations.

```
filter {
	 csv { separator => ","
	           columns => ["loc_lat","loc_lon","proj_lat","proj_lon"]
	 }
	 mutate { add_field => ["[location]", "%{loc_lon}"]
                   add_field => ["[location]", "%{loc_lat}"]
         }
         mutate { convert => ["[location]", "float"]
                   convert => ["[loc_lat]", "float"]
                   convert => ["[loc_lon]", "float"]
                   convert => ["[proj_lat]", "float"]
                   convert => ["[proj_lon]", "float"]
         }
         mutate { add_field => ["[projection][type]", "linestring"]
         }
         ruby { code => "event.set('[projection][coordinates]', [[event.get('loc_lon'), event.get('loc_lat')], [event.get('proj_lon'), event.get('proj_lat')]])"
}

```

Result in cmd with rubedebug:

```
  {          
        "projection" => {
                "coordinates" => [
                    [0] [
                        [0] -74.0446,
                        [1] 40.6899
                    ],
                    [1] [
                        [0] -74.0416,
                        [1] 40.6996
                    ]
                ],
                       "type" => "linestring"
            },
                "location" => [
                    [0] -74.0446,
                    [1] 40.6899
                ]
  }
```

---

<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 6, 2019, 10:34am UTC](https://discuss.elastic.co/t/problem-to-parse-geo-shape-from-csv-trough-logstash/183780/3 "2019-07-06T10:34:40Z")

</div>

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