【问题标题】:elastic search converting and inserting lat lon as geo_point in bulk弹性搜索转换和插入纬度作为geo_point批量
【发布时间】:2016-07-12 12:24:05
【问题描述】:

我有一个简单的csv 文件,它有 4 个字段,serial_num、post_code、lat、lon 例如:

serial_num,post_code,LAT,LON
06AA209365,PE10 2AZ,532342,168459
98A819621,PE10 1AA,532342,168459
07FD490906,PE12 1VV,497882,157983

我需要批量插入elasticsearch。 lat lon 字段需要在单个 geo_point 字段中定义,因此我创建了如下映射:

  • 索引是serial_data
  • 类型是小部件

    PUT /serial_data
    {
    "mappings": {
    "widget": {
      "properties": {
        "serial_number": {
          "type": "string"
        },
        "post_code": {
          "type": "string"
        },
        "location": {
          "type": "geo_point"
        }
      }
    }
    

    } }

我尝试使用embulk 插入数据,因为我认为我有一个定义的映射。如果我将 lat long 定义为 doubles 或 long,那么 embulk 会将 lat, long 解析为单个位置,但它不会,我过于乐观了。

我还认为 embulk 有一个 bulk-input-json 插件,但我找不到它。

问题

任何关于如何批量加载此数据的想法都将不胜感激。

【问题讨论】:

    标签: elasticsearch elasticsearch-plugin


    【解决方案1】:

    我使用树过滤插件。

    • embulk-filter-insert:插入位置列
    • embulk-filter-ruby_proc:结合 LAT 和 LON 列
    • embulk-filter-column:删除 LAT 和 LON 列

    数据.csv

    serial_num,post_code,LAT,LON
    06AA209365,PE10 2AZ,532342,168459
    98A819621,PE10 1AA,532342,168459
    07FD490906,PE12 1VV,497882,157983
    

    conf.yml

    in:
      type: file
      path_prefix: data.csv
      parser:
        charset: UTF-8
        newline: CRLF
        type: csv
        delimiter: ','
        quote: '"'
        escape: '"'
        trim_if_not_quoted: false
        skip_header_lines: 1
        allow_extra_columns: false
        allow_optional_columns: false
        columns:
        - {name: serial_num, type: string}
        - {name: post_code, type: string}
        - {name: lat, type: long}
        - {name: lon, type: long}
    filters:
      - type: insert
        column: 
          location: 
      - type: ruby_proc
        requires:
          - json
        columns:
          - name: location
            proc: |
              ->(_,record) do 
                return { lat: record["lat"], lon: record["lon"] }.to_json.to_s
              end
            skip_nil: false
    
      - type: column
        columns:
          - {name: serial_num}
          - {name: post_code}
          - {name: location}
    
    
    out: {type: stdout}
    

    输出

    +-------------------+------------------+-----------------------------+
    | serial_num:string | post_code:string |             location:string |
    +-------------------+------------------+-----------------------------+
    |        06AA209365 |         PE10 2AZ | {"lat":532342,"lon":168459} |
    |         98A819621 |         PE10 1AA | {"lat":532342,"lon":168459} |
    |        07FD490906 |         PE12 1VV | {"lat":497882,"lon":157983} |
    +-------------------+------------------+-----------------------------+
    

    【讨论】:

      猜你喜欢
      • 2022-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 2018-03-10
      • 2018-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多