I have been a big fan of ElasticSearch for quite some time and I have a
couple of projects where ElasticSearch is "the database" (the data gets
updated infrequently but it needs to be sliced and diced in many different
Lately for one of these project I am getting requests that are more "I need
this report" or "I need this query" and since there is "no SQL database" I
have to write code that queries ElasticSearch (I could use curl, but typing
json by hand is slightly annoying and I always forget the correct syntax
So, this weekend I got tired of editing one more time my "search" script to
change the query and decided to write a tool, you know, for query
Didn't want to invent a new query language, and wanting to enable my
"client" to do his own queries, I decided to start from a SQL parser and
see how far I could take it.
So, here is "elseql", available on github at https://github.com/raff/elseql
It's written in python, so you'll need a reasonably recent version of
python (2.7.x) and a couple of extra packages (it uses rawes for the
If you have the setuptools installed (easy_install and stuff) you should be
able to run "python setup.py install" and be ready to go. Otherwise check
the README for other options.
Right now the main effort has been to implement the "SELECT" statements,
since I need it, you know, for query, but I could potentially add things
like "CREATE TABLE" (put mapping) and "INSERT" (put document).
But there is a "DESCRIBE" command (get mapping) and the mapping is used to
enable command completion (like the mysql client).
The current supported syntax is:
SELECT field1,field2... FROM index WHERE field=value AND|OR
field=value... ORDER BY field1 ASC, field2 DESC LIMIT start,stop
plus a couple of extras:
SELECT field1,field2 FACETS field1, field2 FROM...
SELECT field1,field2,value SCRIPT value='inline script' FROM...
You can check the generated ElasticSearch query and the response by passing
the command line option "--debug" and point to your ElasticSearch
cluster/host with --host=hostname:port (default is localhost:9200)
This is pretty much it for now, but it seems to work and I am adding more
features when I need them. Try it out and let me know. Feel free to email,
post issues on GitHub or add pull requests.