Would you like to learn how to import a CSV file to ElasticSearch? In this tutorial, we are going to show you how to import a CSV file to an ElasticSearch server using Logstash or Kibana.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• ElasticSearch 7.6.2
• Logstash 7.6.2

In our example, The ElastiSearch server IP address is 192.168.100.9.

In our example, we are going to install Logstash and import a CSV file.

Tutorial Logstash – Installation

Use apt-get to install the required packages.

Copy to Clipboard

Find the Java installation directory.

Copy to Clipboard

In our example,  Java is installed on the following directory: /usr/lib/jvm/java-11-openjdk-amd64

Create a file to configure the required Java variables.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Reboot the computer.

Copy to Clipboard

Verify if the system created automatically the environment variable named: JAVA_HOME.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Download and install the ElasticSearch repository key.

Copy to Clipboard

Add the official ElasticSearch repository to your APT database

Copy to Clipboard

Update the APT-GET database and install the Logstash package.

Copy to Clipboard

Configure the Logstash service to start automatically.

Copy to Clipboard

Congratulations! You have finished the Logstash installation on Ubuntu Linux.

Tutorial ElasticSearch – Importing a CSV file

Create a CSV file.

Copy to Clipboard

Here is our file content.

Copy to Clipboard

In our example, we have a CSV file showing the Bitcoin daily price.

Create a Logstash configuration file.

Copy to Clipboard

Here is our file content.

Copy to Clipboard

Stop the Logstash service.

Copy to Clipboard

Star the Logstash service using the new configuration file.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, we imported a CSV file containing 2 fields to ElasticSearch using Logstash.

In our example, we converted the field containing the Bitcoin price to the type numeric float.

In our example, we set the field named DATETIME as the default timestamp.

Verify if the Index was created on the ElasticSearch server.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Verify if the Bitcoin price was mapped as a numeric value.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

In our example, the field named MARKET-PRICE was set as a float number.

List the content of the index named Bitcoin.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You imported a CSV file to ElasticSearch.