0
votes

I have a CSV file which contains Geometries in WKT format. I was trying to ingest geo_shape data using CSV file. I created a mapping as given in file "input_mapping.json"

{
   "mappings" : {
      "doc" : {
        "properties" : {
          "Lot" : {
            "type" : "long"
          },
          "Lot_plan" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "Parcel_Address_Line_1" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "Plan" : {
            "type" : "long"
          },
          "Tenure" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "WKT" : {
            "type" : "geo_shape"
          }
        }
      }
    }
}

WKT is my geo_shape and it is in WKT(String) format. Below is input CSV file which I am trying to insert using logstash:

WKT,Lot_plan,Tenure,Parcel_Address_Line_1,Lot,Plan
"POLYGON ((148.41503356 -26.62829003,148.44798048 -26.62800857,148.45234634 -26.63457929,148.45507096 -26.64778132,148.41735984 -26.64808729,148.41514107 -26.64091476,148.41503356 -26.62829003))",21MM1,FH,MASSEY DOWNS,21,1
"POLYGON ((148.45507096 -26.64778132,148.45779641 -26.66098396,148.45859297 -26.66259081,148.45801376 -26.66410383,148.45989472 -26.67278979,148.42510081 -26.67310328,148.42434355 -26.67065659,148.41735984 -26.64808729,148.45507096 -26.64778132))",21MM2,FH,,21,2
"POLYGON ((148.39514404 -26.68791317,148.37228669 -26.68894235,148.37188338 -26.68895271,148.37092744 -26.68897445,148.37051869 -26.68898023,148.36312088 -26.68908468,148.36261958 -26.66909425,148.39598678 -26.66869309,148.39584372 -26.66934742,148.39583604 -26.66968184,148.39590526 -26.67007957,148.39598629 -26.67039933,148.39614586 -26.67085156,148.39625052 -26.67085085,148.42434355 -26.67065659,148.42510081 -26.67310328,148.42537156 -26.67397795,148.42549108 -26.68541445,148.41781484 -26.68547248,148.39988482 -26.68562107,148.39966009 -26.68562292,148.39704234 -26.68564442,148.39514404 -26.68791317))",21MM3,LL,DERWENT PARK,21,3

And my logstash conf file is :

input{
file{
        path=>"D:/input.csv"        
        start_position=>"beginning"
        sincedb_path=>"D:/sample.text"

    }
}                                   
filter{
csv{
        separator =>"," 
        columns =>["WKT","Lot_plan","Tenure","Parcel_Address_Line_1","Lot","Plan"]
        skip_header=>true
        skip_empty_columns=>true
        convert => {
          "Lot" => "integer"
          "Plan" => "integer"                                 
        }
        remove_field =>[ "_source","message","host","path","@version","@timestamp"  ]


}

}
output{
    elasticsearch{
        hosts=>"http://localhost:9701" 
        index=>"input_mapping"
        template =>"D:/input_mapping.json"
        template_name => "input_mapping"
        manage_template => true
    }
}

Due to some reason it is not getting ingested in the ElasticSearch. I am using ElasticSearch version 6.5.4 and logstash version 6.5.4. Kindly let me know if I have missed anything.

1
Nice job so far! It worked out perfectly for me. Try not to specify any sincedb_path value. - Val

1 Answers

0
votes

I realized there will be many other developers who would be looking for problem similar which I had faced it. Later point of time, I checked GDAL( ogr2ogr) which provides ElasticSearch ingestion. Also I use PostgreSQL to ingest the CSV file. Therefore using ogr2ogr tool helps me by following the below steps:

  1. First ingest my CSV file in PostgreSQL where I put WKT as text column in a table.
  2. Create another column within the table and updated this column with ST_GeomFromText function.

    update TableName set WKT_GEOM=ST_GeomFromText("WKT",4632)

    (Note: I already installed the postgis in PostgreSQL)

  3. Now I start my ElasticSearch.
  4. Using ogr2ogr by following the examples provided:

    a.First create elasticsearch mapping using ogr2ogr.

    b.Now ingest the data from PostgreSQL to ElasticSearch.

    https://gdal.org/drivers/vector/elasticsearch.html

In this way, I was able to perform geoquery in Elasticsearch. But unfortunately it was without logstash. :(

Please comment if you have any doubts.