Skip to content

newgene/tornado-es

 
 

Repository files navigation

Build Status

Tornado-es

A tornado-powered python library that provides asynchronous access to elasticsearch.

Install

Via pip:

pip install tornadoes

Usage

Indexing a dummy document:

$ curl -XPUT 'http://localhost:9200/index_test/typo_test/1' -d '{
    "typo_test" : {
        "name" : "scooby doo"
    }
}'

Tornado program used to search the document previously indexed:

# -*- coding: utf-8 -*-

import json

import tornado.ioloop
import tornado.web

from tornadoes import ESConnection


class SearchHandler(tornado.web.RequestHandler):

    es_connection = ESConnection("localhost", 9200)

    @tornado.web.asynchronous
    def get(self, indice="index_test", tipo="typo_test"):
        query = {"query": {"match_all": {}}}
        self.es_connection.search(callback=self.callback,
                                  index=indice,
                                  type=tipo,
                                  source=query)

    def callback(self, response):
        self.content_type = 'application/json'
        self.write(json.loads(response.body))
        self.finish()

application = tornado.web.Application([
    (r"/", SearchHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

About

A tornado-powered python library that provides asynchronous access to elasticsearch

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 97.5%
  • Shell 2.5%