You need to log in to create posts and topics.

Defining Custom Field Mapping Types

If Elasticsearch can't determine which mapping type a field should be, it will default that field to a String type. Click here for a full list of available field datatypes.

When importing a CSV file, you may need to define custom field types before importing in order to take advantage of the different types of queries you can make with the different field types . You can always add new fields, but you can't change the type or the analyzer for an existing field. After the file is uploaded, changing the mappings is possible, but only backwards compatible changes can be applied by using multi-fields.

You only need to specify the custom field types that you want to behave differently from the default.

This guide will use a sample Sales.csv file to demonstrate how to define custom mappings before importing to Elasticsearch and It assumes that you have already downloaded and installed the ABC-Import tool in the other instructional. If not, please go through that tutorial, install it. and then come back here to import the file. 


1. Create the Mapping file. This will be done by creating a JavaScript file called mappings.js in the linux terminal.

sudo vim mappings.js


2. Edit the mappings.js file .

The Sales.csv file has the following properties that we need to define mapping types for:

  • Order ID
  • Total Cost
  • Total Profit
  • Total Revenue
  • Unit Cost
  • Unit Price
  • Units Sold
  • Country
  • Order Date
  • Order Priority
  • Region
  • Sales Channel
  • Ship Date

Save the file and quit.


4. In the terminal, run ABC Import command tool as usual while adding  --transform_file="mappings.js".

./abc-linux import --src_type=csv --src_uri="Sales.csv" --typename=sales --transform_file="mappings.js" <Elasticsearch API Endpoint>/sales


5. Locate the data in the platform.

In the platform, click on the "Discover" tab. Enter the name of the index* that was previously defined which should match automatically. Click on "Next" followed by "Create Index Pattern".  


6. Check that the custom mappings have been indexed correctly. 

Looks like a success!


7. Click on the "Discover" tab to see your newly imported CSV file.

The next tutorial will show how we can create custom visualizations in the Kibana dashboard based on these field types.