Can I run elasticsearch-sql-cli in batch mode?


#1

Hello All,

Is there anyway I can run the sql-cli in batch mode with a sql statement that I can redirect into it(I can't, I tried).

I guess I can use the python elasticsearch_dsl module to run the output and generate jsons, but any pointers to documentation is greatly appreciated.

I also noticed the sql-cli doesn't like "-" in index names, once I created an alias with "_" things worked fine.

GT


(Tim Vernum) #2

As far as I know there's no batch/non-interactive mode for the CLI, but everything done through the CLI can be done through the REST API, so you could just as easily automate with curl, or your favourite HTTP client.

Due to the SQL syntax, "-" is parsed as a subtraction operator. If your index names have "-" in them, then you need to wrap the whole index name in quotes:

SELECT count(*) from "logstash-2018-06-20"

or even

SELECT count(*) from "logstash-*"

#3

Ok, here goes.

When I try to run this, once I again I get an error, what am I doing wrong?

POST _xpack/sql?format=txt{
'query' : 'SELECT * from "m-bod-daily" LIMIT 5'
}


#4

Ok, if somebody else has a similar question, here's the solution.

POST _xpack/sql?format=txt
{
"query" : "SELECT cloud, instance, mach00_nRxAppPkts from \"stats-m-bod-daily\" LIMIT 5"
}


(system) #5

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