======
SlimES
======

Thin Python client for Elasticsearch
====================================

This is a little wrapper over the `requests <http://docs.python-requests.org/en/latest/index.html>`_ module that helps you do your thing with Elasticsearch. But not too much. For each request, you need to specify the following, where they are applicable:

* desired request method

* index, type, ID

* "suffix" (which might be the _search, _bulk, etc at the end of the URL)

* a dictionary or a string with the data you want to submit


Why would I want that?
======================

Two reasons:

* flexibility - the point of this client is to keep up with the many features constantly added to Elasticsearch. You can customize your index operations and queries as much as you need

* documentation - once you get the hang of the few options particular to this client, you only have to look at the documentation on Elasticsearch itself to access its features

If this is not what you want, I would suggest to look at `pyes <https://github.com/aparo/pyes>`_ or `pyelasticsearch <https://github.com/rhec/pyelasticsearch>`_

Features and usage
==================

There are a few files in there at the moment:

* slimes.py - the module itself

* tests_slimes.py - unit tests

Here are the main features:

Converts your dict to JSON (you can disable that for stuff like bulks)
----------------------------------------------------------------------

::

    #!/usr/bin/env python
    import slimes
    my_requester = slimes.Requester(["localhost:9200"])
    #define the document
    testdoc = {"foo": 2345, "bar": True}
    #post the document
    my_requester.request(method="post",
        myindex="testindex",
        mytype="testtype",
        mydata=testdoc)

Can get a list of nodes, for redundancy
---------------------------------------

::

    #!/usr/bin/env python
    import slimes
    my_requester = slimes.Requester(["localhost:9200","my_other_server:9200"])

Loads the JSON results for you
------------------------------

If something goes wrong (eg: non 2XX status code), you'll get an exception. Otherwise, you'll get a dictionary with the results from ES::

    #!/usr/bin/env python
    import slimes
    my_requester = slimes.Requester(["localhost:9200"])
    myquery = {\
    	"query": {\
    		"term": {\
    			"age": 28\
    		}\
    	}\
    }
    results = my_requester.request(method="post",
    	myindex="testindex",
    	mytype="testtype",
    	mysuffix="_search",
    	mydata=myquery)
    print "Number of hits is %d" % result['hits']['total']

Can receive parameters as a suffix
----------------------------------

So you can index with the "create" parameter, like this::

    #!/usr/bin/env python
    import slimes
    my_requester = slimes.Requester(["localhost:9200"])
    testdoc={"foo": "bar"}
    my_requester.request(method="put",
    	myindex="testindex",
    	mytype="testtype",
    	myID=1,
    	mysuffix="?op_type=create",
    	mydata=testdoc)

TODOes
======

Enhancements will be about the transport. Stuff like:
- use thrift
- get all cluster nodes

Stay tuned :)

Bugs
====

Please feel free to report them on `github <https://github.com/radu-gheorghe/slimes/issues>`_
