Running elasticsearch-sql-cli Script on Remote Machines

Hello again Elasticsearch wizards,

I have what is probably a stupid Java question. I’ve spun up a Docker container of Elasticsearch v7.4.0, and I’m loving the “elasticsearch-sql-cli” script you can use to submit SQL-like queries to ES. Great stuff! The only hitch is, I have to run the script from within the container.

The online documentation (here) says “The jar containing [elasticsearch-sql-cli] is a stand alone Java application and the scripts just launch it. You can move it around to other machines without having to install Elasticsearch on them.” That sounded great. So I copied “elasticsearch-sql-cli,” the Java Jar file, plus two other files that “elasticsearch-sql-cli” referenced. (“elasticsearch-env” and “x-pack-env,” all in ES_HOME/bin/)

Of course, when transplanted to a remote machine, the script did not work. (Yes, the remote machine can ping the ES Docker container.) I took a look at “elasticsearch-sql-cli,” saw that it statically pointed to the other files in their original file locations, and then edited the script:

#!/bin/bash

# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License;
# you may not use this file except in compliance with the Elastic License.

source /home/me/es_sql_script/elasticsearch-env

source /home/me/es_sql_script/x-pack-env

CLI_JAR="/home/me/es_sql_script/elasticsearch-sql-cli-7.4.0.jar"

exec \
  "$JAVA" \
  -jar "$CLI_JAR" \
  "$@"

But of course, that didn’t work, either. So I wonder if I’m misunderstanding what the documentation means when it says “You can move it around to other machines.” Am I to just move the jar file and write a Java wrapper program that launches it? Or is it meant to be executed directly from the command line? I (obviously) don’t know much about jar files, but I don’t think Elastic intended either of those as solutions.

Any advice is appreciated.

@redapplesonly I don't think you need the script. Can you try ./java -cp elasticsearch-sql-cli-7.4.0.jar org.elasticsearch.xpack.sql.cli.Cli http://localhost:9200 ? (changing the url to your node accordingly, of course)

And I agree with you, the docs are not clear. I followed the steps I assumed the docs are suggesting and ended up with an unworking cli (appeared to be hanging).

Thanks Andrei,

I didn't mean to imply that the documentation was unclear. I write technical docs myself, and frequently, I summarize things that are very clear to me, but may not be for my readers. My sense is that is what happened here.

I tried your suggestion, but the "org.elasticsearch.xpack.sql.cli.Cli" package seems to be a stumbling block:

me@ubuntu1:~#
me@ubuntu1:~# java -cp ./elasticsearch-sql-cli-7.4.0.jar org.elasticsearch.xpack.sql.cli.Cli http://10.10.10.10:9200
Error: Could not find or load main class org.elasticsearch.xpack.sql.cli.Cli
me@ubuntu1:~#

I'm unclear if your command would instruct Java to download the package or try to access it from a local file. When I went online and looked for that file, and found two links, here and here. Neither seemed to be what I as looking for, however. At least your version ran, even if it hung.

I suspect there isn't a viable solution or workaround for this yet. Can you point me to where I could make a suggestion for submit a bug for future versions of ES? Thank you!

@redapplesonly that jar file should come with your Elasticsearch installation. And you mentioned it already in your attempts to make this work... CLI_JAR="/home/me/es_sql_script/elasticsearch-sql-cli-7.4.0.jar" one of those mentions.

The CLI class resides in this jar file and when using java -cp it's telling java to use in its classpath the jar file mentioned above, go look inside for the Cli.class file and use that.

Thanks Andrei,

I actually got it to work with a simpler solution:

me@ubuntu1:~# java -jar ./elasticsearch-sql-cli-7.4.0.jar 10.10.10.10:9200

It took a little while to connect, but then worked great. Thanks for the help, really appreciate it...!

Thanks Andrei! Much appreciated...!