【问题标题】:Adding Geo_shape to Elasticsearch using Logstash使用 Logstash 将 Geo_shape 添加到 Elasticsearch
【发布时间】:2019-03-05 01:31:29
【问题描述】:

我有一个 CSV 文件,其中包含 WKT 格式的几何图形。我试图使用 CSV 文件摄取 geo_shape 数据。我创建了文件“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 是我的 geo_shape,它是 WKT(String) 格式。 下面是我尝试使用 logstash 插入的输入 CSV 文件:

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

我的 logstash conf 文件是:

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
    }
}

由于某种原因,它没有被 ElasticSearch 摄取。我正在使用 ElasticSearch 6.5.4 版和 logstash 6.5.4 版。 如果我遗漏了什么,请告诉我。

【问题讨论】:

  • 到目前为止做得很好!它对我来说非常完美。尽量不要指定任何sincedb_path 值。

标签: elasticsearch logstash logstash-configuration


【解决方案1】:

我意识到会有许多其他开发人员会寻找与我遇到过类似的问题。后来,我检查了提供 ElasticSearch 摄取的 GDAL(ogr2ogr)。我也使用 PostgreSQL 来摄取 CSV 文件。因此,使用 ogr2ogr 工具可以帮助我按照以下步骤操作:

  1. 首先在 PostgreSQL 中提取我的 CSV 文件,我将 WKT 作为文本列放入表中。
  2. 在表中创建另一列,并使用 ST_GeomFromText 函数更新此列。

    更新 TableName 集 WKT_GEOM=ST_GeomFromText("WKT",4632)

    (注意:我已经在PostgreSQL中安装了postgis)

  3. 现在我开始我的 ElasticSearch。
  4. 按照提供的示例使用 ogr2ogr:

    a.首先使用ogr2​​ogr创建elasticsearch映射。

    b.现在将数据从 PostgreSQL 摄取到 ElasticSearch。

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

通过这种方式,我能够在 Elasticsearch 中执行地理查询。但不幸的是它没有logstash。 :(

如果您有任何疑问,请发表评论。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 1970-01-01
    • 2015-01-01
    • 2016-12-10
    • 2015-08-31
    • 2021-05-02
    • 2022-12-06
    相关资源
    最近更新 更多