GithubHelp home page GithubHelp logo

am2rican5 / tornado_elasticsearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gmr/tornado-elasticsearch

0.0 2.0 0.0 91 KB

Extends the official Elasticsearch Python API adding Tornado AsyncHTTPClient support

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

tornado_elasticsearch's Introduction

tornado_elasticsearch

Extends the official Elasticsearch Python API adding Tornado AsyncHTTPClient support.

Version Downloads License

Installation

tornado_elasticsearch is available on the Python Package Index and can be installed using pip or easy_install:

pip install tornado_elasticsearch

Example Request Handlers

from tornado import gen
from tornado import web
from tornado_elasticsearch import AsyncElasticsearch
import uuid

class Example(web.RequestHandler):

    def initialize(self):
        self.es = AsyncElasticsearch()

    @web.asynchronous
    @gen.engine
    def delete(self, *args, **kwargs):
        result = yield self.es.delete(index='test-index', doc_type='tweet',
                                      id=self.get_argument('id'))
        self.finish(result)

    @web.asynchronous
    @gen.engine
    def get(self, *args, **kwargs):
        if self.get_argument('id', None):
            result = yield self.es.get(index='test-index', doc_type='tweet',
                                       id=self.get_argument('id'))
        else:
            result = yield self.es.search(index='test-index')
        self.finish(result)

    @web.asynchronous
    @gen.engine
    def post(self, *args, **kwargs):
        doc = {
            'author': self.get_current_user() or 'Unknown',
            'text': self.get_argument('text'),
            'timestamp': datetime.datetime.now()
        }
        result = yield self.es.index(index='test-index',
                                     doc_type='tweet',
                                     body=doc,
                                     id=str(uuid.uuid4()))
        self.finish(result)


class Info(web.RequestHandler):

    @web.asynchronous
    @gen.engine
    def get(self, *args, **kwargs):
        es = AsyncElasticsearch()
        info = yield es.info()
        self.finish(info)

Version History

  • 0.3.0: Bugfix: Add body to log_request_fail call (#1)
  • 0.2.0: Bugfix: force method to POST if GET and body passed
  • 0.1.0: Initial version

tornado_elasticsearch's People

Contributors

gmr avatar

Watchers

James Cloos avatar Lee Hyeon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.