Loading...

Import Currency codes into Elasticsearch

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Working in the financial business requires to have the currency code master-data accessible for various reasons. The ISO 4217 currency codes can be obtained from the ISO Organization website. This post uses Logstash and the csv plugin to process the data and import it into Elasticsearch. Elasticsearch itself provides the REST interface, so every micro-service or web service can access the desired data.

Export the data from Excel to CSV. This logstash configuration reads the CSV data, converts it and ships it to elasticsearch. Alter the values to your scenario.

input {
  file {
    path => "/tmp/currencies.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
    columns => ["entity", "currency", "alphaCode", "id", "numericCode", "minorUnit"]
    separator => ";"
  }
  mutate {
    remove_field => "message"
    convert => {
        "numericCode" => "integer"
        "minorUnit" => "integer"
    }
    add_field => {
        "[meta][edition]" => "ISO 4217:2015"
    }
    replace => {
        "id" => "%{alphaCode}-%{entity}"
    }
  }
}
output {
  stdout { codec => "rubydebug" }
  elasticsearch {
    hosts => [ "elasticsearch:9200" ]
    user => "elastic"
    password => "changeme"
    index => "masterdata"
    document_type => "currency"
    document_id => "%{id}"
  }
}
Please remember the terms for blog comments.