Would you like to learn how to use the ElasticSearch authentication using an API? In this tutorial, we are going to show you how to create an API and use it to perform queries to the ElasticSearch server.

• Ubuntu 18
• Ubuntu 19
• ElasticSearch 7.6.2

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

Tutorial ElasticSearch - Authentication API

Install the required packages.

Copy to Clipboard

Test your communication with the ElasticSearch server.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Keep in mind that the API based authentication requires an HTTPS connection to ElasticSearch.

To enable the API based authentication, you need to create a certificate and enable the following features on the Elasticsearch configuration file.

Copy to Clipboard

Create an ElasticSearch API.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

In our example, we created an authentication API to the user account named: Elastic.

• API ID - l1YNpHEB5GTDEAepLnnx
• API KEY - 40kYGW-SRZG2KnL_dWkBSQ

Important! We used the HTTPS protocol instead of the HTTP. 

We need to encode the ID and KEY using Base64.

• API ID - l1YNpHEB5GTDEAepLnnx
• API KEY - 40kYGW-SRZG2KnL_dWkBSQ

Important! You need to separate the ID and KEY using the colon character.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Use the API to perform a query to the ElasticSearch server.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Use the API to perform a query to the ElasticSearch server with verbose.

Copy to Clipboard

Here is the command output:

Copy to Clipboard

Congratulations! You are able to use an ElasticSearch API for authentication.