Elastic Search

Resolve Expected Errors While Connecting With Elasticsearch-sql-cli

Elasticsearch is a free, open-source, and well-known analytical search engine that analyzes and manages different types of data. It is purely a NoSQL database and search engine. However, its Xpack component offers the Elasticsearch SQL interface that enables its users to utilize SQL queries. In “elasticsearch-sql-cli” users can purely utilize the SQL queries to search data from Elasticsearch indices.

Many Elasticsearch users complain about unexpected errors that occur while executing the “elasticsearch-sql-cli” interface on the system and may not be able to understand and resolve them.

In this post, we will demonstrate how to resolve expected errors while connecting with “elasticsearch-sql-cli”.

How to Resolve Expected Errors While Connecting With “elasticsearch-sql-cli”?

The most common error that users usually face while executing the “elasticsearch-sql-cli” is “Cannot communicate with the server https://localhost:9200. This version of the CLI only works with the Elasticsearch version 8.7.0”. Even though, users are running the same version on the system.

Another difficulty that users can face while running the “elasticsearch-sql-cli” is “Communication error [Cannot POST address https://localhost:9200/_sql”. This error occurs due to some users running Elasticsearch on “HTTP” and some on “HTTPS”.

To resolve all the expected errors while connecting with Elasticsearch SQL CLI, follow these steps.

Step 1: Run Elasticsearch Engine

First, run the Elasticsearch engine on the system. For this purpose, navigate to the “bin” directory of Elasticsearch through the “cd” command:

d C:\Users\Dell\Documents\Elasticsearch\elasticsearch-8.7.0\bin

 

Next, run the batch file of Elasticsearch using the given command:

elasticsearch.bat

 

Next, verify whether the Elasticsearch is executing on the system or not by navigating to the “localhost:9200” URL:

The above output shows that Elasticsearch is running successfully. Now, the user can execute the Elasticsearch SQL interface.

Step 2: Access Elasticsearch SQL CLI

Now, execute the “elasticsearch-sql-cli” command to start executing the SQL interface of Elasticsearch:

elasticsearch-sql-cli

 

Here, you can see we have encountered the error message “This version of CLI only works with Elasticsearch version 8.7.0”. Even, we are using the same version to run “elasticsearch-sql-cli”:

Another possible way to start the Elasticsearch SQL CLI is by adding the Elasticsearch user credentials along with the “elasticsearch-sql-cli” command:

elasticsearch-sql-cli https://elastic:<user-password>@localhost:9200

 

But still, the error is there as shown below:

Note: The specified error occurs due to an unknown reason and confuses the users whether they are using the same version or not. This error can be resolved by embedding some options along with the command.

Step 3: Resolve “ERROR: Cannot communicate with the server https://localhost:9200. This version of the CLI only works with the Elasticsearch version <version-no>”

To fix the stated error, utilize the “elasticsearch-sql-cli” command along with the following options:

  • -c” is utilized to permit the initial connection check.
  • -d” permits the debug logging.
  • -v” displays the verbose output:
elasticsearch-sql-cli https://elastic:<user-password>@localhost:9200 -c -d -v

 

Step 4: Verification

By executing the above command, the “Elasticsearch SQL” interface will be opened on the screen as shown below:

We have successfully resolved the “Cannot communicate with the server https://localhost:9200. This version of CLI only works with Elasticsearch version 8.7.0” error.

Step 5: Execute SQL Query

Here, users can run the SQL queries directly to search the data from Elasticsearch indices. But at this point, the user may encounter an error while executing the SQL query:

SELECT * FROM employee;

 

Similarly, we have encountered the “Communication error”:

Note: The “Communication error [Cannot POST address https://localhost:9200/_sql?error_trace (Unsupported or unrecognized SSL message)]” error occurs when the SQL query is unable to access the searched indices or Elasticsearch on the local host. This is due to some users using Elasticsearch with “HTTP” protocol and some accessing Elasticsearch with “HTTPS” protocol.

To fix this problem, first exit the SQL interface using the “exit” command:

exit;

 

Step 6: Resolve “Communication error [Cannot POST address https://localhost:9200/_sql?error_trace (Unsupported or unrecognized SSL message)]” Error

Now, again access the Elasticsearch SQL interface by switching the “HTTPS” protocol to “HTTP” protocol to access Elasticsearch:

elasticsearch-sql-cli http://elastic:<user-password>@localhost:9200 -c -d -v

 

Step 7: Run SQL Query

Now, again execute the SQL query and check if the error is resolved or not:

SELECT * FROM employee;

 

The below output shows that we have resolved all the errors and executed the SQL query successfully in the Elasticsearch SQL interface:

That’s all about resolving expected errors while connecting with “elasticsearch-sql-cli”.

Conclusion

While executing “elasticsearch-sql-cli” to access the Elasticsearch SQL interface, users may encounter some errors such as “This version of CLI only works with Elasticsearch version <version-no>” or “Communication error”. In the blog, we have provided a step-by-step guide to resolve all the possible errors that can occur while connecting with elasticsearch-sql-cli.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.