# Running elasticsearch-sql-cli Script on Remote Machines

**URL:** <https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [October 24, 2019, 7:32pm UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143 "2019-10-24T19:32:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![redapplesonly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redapplesonly/32/57700_2.png) [@redapplesonly](https://discuss.elastic.co/u/redapplesonly)\
**Post date:** [October 24, 2019, 7:32pm UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143/1 "2019-10-24T19:32:35Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/sql-cli.html)) 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.

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [October 25, 2019, 7:13am UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143/2 "2019-10-25T07:13:08Z")

</div>

@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).

---

<div class="post-metadata">

**Author:** ![redapplesonly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redapplesonly/32/57700_2.png) [@redapplesonly](https://discuss.elastic.co/u/redapplesonly)\
**Post date:** [October 28, 2019, 6:29pm UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143/3 "2019-10-28T18:29:26Z")

</div>

> [@Andrei\_Stefan](#):
>
> ./java -cp elasticsearch-sql-cli-7.4.0.jar org.elasticsearch.xpack.sql.cli.Cli [http://localhost:9200](http://localhost:9200)

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](https://www.elastic.co/downloads/jdbc-client) and [here](https://artifacts.elastic.co/maven/org/elasticsearch/plugin/x-pack-sql-jdbc/7.4.1/x-pack-sql-jdbc-7.4.1.jar). 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!

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [October 29, 2019, 12:25pm UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143/4 "2019-10-29T12:25:59Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![redapplesonly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redapplesonly/32/57700_2.png) [@redapplesonly](https://discuss.elastic.co/u/redapplesonly)\
**Post date:** [October 29, 2019, 7:19pm UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143/5 "2019-10-29T19:19:25Z")

</div>

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...!

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [October 31, 2019, 4:15am UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143/6 "2019-10-31T04:15:52Z")

</div>

> <https://github.com/elastic/elasticsearch/issues/48729>
>
> Our documentation on the SQL CLI has few issues (a bit of background here):
> The jar containing the SQL CLI is a...

---

<div class="post-metadata">

**Author:** ![redapplesonly](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redapplesonly/32/57700_2.png) [@redapplesonly](https://discuss.elastic.co/u/redapplesonly)\
**Post date:** [October 31, 2019, 12:39pm UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143/7 "2019-10-31T12:39:03Z")

</div>

Thanks Andrei! Much appreciated...!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 28, 2019, 12:47pm UTC](https://discuss.elastic.co/t/running-elasticsearch-sql-cli-script-on-remote-machines/205143/8 "2019-11-28T12:47:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
