Elasticsearch 的 Python 客户端:tina

jopen 9年前

Elasticsearch 的 Python client,提供较为方便的查询语法。

Installation

$ git submodule add https://github.com/kelp404/tina.git  $ git submodule add https://github.com/kelp404/elasticsearch-py.git  $ pip3 install urllib3  $ pip3 install certifi  $ pip3 install ujson

Django settings

# settings.py TINA_ELASTICSEARCH_URL = 'https://username:password@domain.com:9200' TINA_INDEX_PREFIX = 'prefix_' # The prefix of the index name.

Document

# example:  from tina import db  # define your data model  class SampleModel(db.Document):      _index = 'samples'  # You can set index name by this attribute.      name = db.StringProperty()      email = db.StringProperty(required=True)      is_vip = db.BooleanProperty(default=False)      quota = db.FloatProperty(default=0.0)      created_at = db.DateTimeProperty(auto_now=True)

Properties

_id: {string}  _version: {int}

Methods

     def get(cls, ids, rev=None, db=None, dynamic_properties=True):          """          Get documents by ids.          :param ids: {list or string} The documents' id.          :return: {list or Document}          """      # example:      #    Get the document by the id.      #    The result document is SampleModel's instance.          document = SampleModel.get('byMQ-ULRSJ291RG_eEwSfQ')      #    Get the documents by ids.      #    The result documents is the list. There are SampleModels' instance in the list.          documents = SampleModel.get([              'byMQ-ULRSJ291RG_eEwSfQ',              'byMQ-ULRSJ291RG_eEwSfc',          ])        def exists(cls, id):          """          Is the document exists?          :param id: {string} The documents' id.          :return: {bool}          """          is_exist = SampleModel.exists('byMQ-ULRSJ291RG_eEwSfQ')        def where(cls, *args, **kwargs):          """          Intersect the query.          :param args:              The member's name of the document or                  the sub queries' lambda function.          :param kwargs: [              unequal,              equal,              less,              less_equal,              greater,              greater_equal,              like,              unlike,              contains,              exclude,          ]          :return: {tina.query.Query}          """        def all(cls):          """          The query for all documents.          :return: {tina.query.Query}          """        def refresh(cls):          """          Explicitly refresh the index, making all operations performed          """        def save(self, synchronized=False):          """          Save the document.          """        def delete(self, synchronized=False):          """          Delete the document.          """

项目主页:http://www.open-open.com/lib/view/home/1441012024721

</strong>