<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Matheus Warmeling on Medium]]></title>
        <description><![CDATA[Stories by Matheus Warmeling on Medium]]></description>
        <link>https://medium.com/@matheuswarmeling?source=rss-ead6891bbb28------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*kRJryEQvf54-2Y63.</url>
            <title>Stories by Matheus Warmeling on Medium</title>
            <link>https://medium.com/@matheuswarmeling?source=rss-ead6891bbb28------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:52:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matheuswarmeling/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Logstash to import CSV Files Into ElasticSearch with Docker.]]></title>
            <link>https://medium.com/@matheuswarmeling/using-logstash-to-import-csv-files-into-elasticsearch-with-docker-ccdae1b1d4e6?source=rss-ead6891bbb28------2</link>
            <guid isPermaLink="false">https://medium.com/p/ccdae1b1d4e6</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[logstash]]></category>
            <category><![CDATA[csv]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Matheus Warmeling]]></dc:creator>
            <pubDate>Tue, 19 Feb 2019 19:50:29 GMT</pubDate>
            <atom:updated>2020-02-26T11:35:42.579Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tG94d446FeaQcd0b5ni8fw.png" /></figure><h3>Prerequisites</h3><p>I will assume that you have already downloaded Docker, Elasticsearch and that take running in localhost.</p><h3>Creating Configuration</h3><p>We will need creating two files on the same folder, you can start creating file “starting.conf”. Inside the file, you’ll need to write the config below as an example. You’ll need to replace some values to work.</p><pre>input {<br>  file {<br>    path =&gt; &quot;/usr/share/logstash/file.csv&quot;<br>    start_position =&gt; &quot;beginning&quot;<br>    codec =&gt; plain {<br>            charset =&gt; &quot;ISO-8859-1&quot;<br>    }<br>  }<br>}<br>filter {<br>  csv {<br>    separator =&gt; &quot;,&quot;<br>    columns =&gt; [&quot;id&quot;, &quot;city&quot;, &quot;country&quot;]<br>  }<br>}<br>output {<br>	elasticsearch {<br>		action       =&gt; &quot;index&quot;<br>		hosts =&gt; [&quot;http:localhost:9200&quot;]<br>		index =&gt; &quot;city&quot;<br>		document_type =&gt; &quot;city&quot;<br>	}<br>   stdout {<br>    codec =&gt; rubydebug<br>  }}</pre><p>We are speaking about first blockcode input.</p><pre>input {<br>  file {<br>    path =&gt; &quot;/usr/share/logstash/file.csv&quot;<br>    start_position =&gt; &quot;beginning&quot;<br>    codec =&gt; plain {<br>            charset =&gt; &quot;ISO-8859-1&quot;<br>    }<br>  }<br>}</pre><p>The path setting is required and must be an absolute path, or the full path to the file. We can stay with “/usr/share/logstash/”, because we run with docker. We need just replace “file.csv” to your csv.</p><p>Lastly, we specify the starting_position option. Here, we are setting it to the beginning because if we have not seen a file before, we want it to start at the beginning and import all of the data in the file and then watch for changes to the end of it. By default, this is set to end and really treats files just as though they are live streams which get added onto.</p><p>The <a href="https://www.elastic.co/guide/en/logstash/current/plugins-codecs-plain.html#plugins-codecs-plain-options">codec </a>is for plain text with no delimiting between events. This is mainly useful on inputs and outputs that already have a defined framing in their transport protocol (such as zeromq, rabbitmq, redis, etc)</p><p>Second blockcode filter.</p><pre>filter {<br>  csv {<br>    separator =&gt; &quot;,&quot;<br>    columns =&gt; [&quot;id&quot;, &quot;city&quot;, &quot;country&quot;]<br>  }<br>}</pre><p>The separator, that we use is how we tell Logstash what the character that separates column is. This actually defaults to “,” as we set it, but I include this setting in the configuration file so that it is clear to anybody reading the file.</p><p><a href="http://logstash.net/docs/1.4.2/filters/csv#columns">T</a>he column, allows us to specify the names of the columns in our file csv.</p><p>Now that we have our data setup to be brought into Logstash, then parsed and processed, now we need to specify what to do with the data once it’s been parsed. To do this we use the Output codeblock below:</p><pre>output {<br>	elasticsearch {<br>		action       =&gt; &quot;index&quot;<br>		hosts =&gt; [&quot;http:localhost:9200&quot;]<br>		index =&gt; &quot;city&quot;<br>		document_type =&gt; &quot;city&quot;<br>	}<br>   stdout {<br>    codec =&gt; rubydebug<br>  }}</pre><p>Here, we are using the elasticsearch output and specifying four options: action, host, index, and document_type.</p><p>We begin by setting the action we would like ElasticSearch to perform which can be either “index” or “delete”. “index” is the default value for this option.</p><p>Secondly, we set the host option which tells logstash the hostname or IP address to use for ElasticSearch unicast discovery.</p><p>Third, we set the index and type option which allows us to specify what ElasticSearch index/type we would like to write our data to.</p><h3>Creating Dockerfile</h3><p>We need to create a Dockerfile with the configuration below. We must create Dockerfile on the same paste of file.csv and starting.conf.</p><pre>FROM docker.elastic.co/logstash/logstash:6.3.1</pre><pre>COPY file.csv ./<br>COPY starting.conf ./</pre><p>The FROM we are using the image logstash 6.3.1 and the parameter COPY, we are copy files to inside docker.</p><p>Now we are need run command below to create an image.</p><pre>docker build -t logstash:latest .</pre><h3>Running our configuration</h3><p>We should run docker with the command below. The property -it views in command makes access to the docker.</p><pre>docker run --entrypoint &quot;/bin/sh&quot; -it logstash:latest</pre><p>Now that we are inside docker, we need running the command below to running configuration</p><pre>bin/logstash -f starting.conf --verbose</pre><p>After running the last command, your csv will be inserted on elasticsearch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ccdae1b1d4e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>