| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

Elasticsearch 的 Python 客户端:tina

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>

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1441012024721.html
ElasticSearch 搜索引擎