{ "info": { "author": "Santiago Saavedra", "author_email": "ssaavedra@openshine.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": ".. image:: https://travis-ci.org/openshine/python-esqb.svg?branch=master\n :target: https://travis-ci.org/openshine/python-esqb\n\n===========================\nElasticSearch Query Builder\n===========================\n\nA Query Builder to build queries specially suited for ElasticSearch queries\n\nExamples\n--------\n\nBasic example\n+++++++++++++\n\nThis code show how to define a simple query.\n\n.. code-block:: python\n\n from esqb.query import BaseQuery\n\n\n class SimpleQuery():\n size = 0\n query = {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"name\": {\n \"value\": \"esqb\"\n }\n }\n }\n ]\n }\n }\n aggs = {\n \"by_logtime\": {\n \"date_histogram\": {\n \"field\": \"time\",\n \"interval\": \"day\",\n \"order\": {\n \"_key\": \"desc\"\n }\n }\n }\n }\n\nand this is the generated query.\n\n.. code-block:: json\n\n {\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"name\": {\n \"value\": \"esqb\"\n }\n }\n }\n ]\n }\n },\n \"size\": 0,\n \"aggs\": {\n \"by_logtime\": {\n \"date_histogram\": {\n \"field\": \"time\",\n \"interval\": \"day\",\n \"order\": {\n \"_key\": \"desc\"\n }\n }\n }\n },\n \"sort\": []\n }\n\nVariables and filters\n+++++++++++++++++++++\n\nExample to create a query to show the the last **N** documents ordered by a **sort_field** between two dates (**ts** and **te**)\n\nv.py\n^^^^\n\nThis file show how to define the query variables.\n\n.. code-block:: python\n\n from esqb.variable import Variable\n\n\n ts = Variable('ts', None, str, True, 'Time start')\n te = Variable('te', '2017-12-01', str, True, 'Time end')\n size = Variable('query_size', 10, str, False, 'Term size')\n sort_field = Variable('sort_field', '', str, True,\n 'Field to do the ordination')\n sort_order = Variable('sort_order', '', str, True, 'asc or desc')\n variables = {\n v.name: v.name for v in [\n ts,\n te,\n size,\n sort_field,\n sort_order\n ]\n }\n\nfilters.py\n^^^^^^^^^^\n\nThis file show how to define a esqb query filter to add a date range.\n\n.. code-block:: python\n\n from esqb.queryfilter import QueryFilter\n\n\n class time_range_filter(QueryFilter):\n \"\"\"\n Query filter to filter between two dates.\n \"\"\"\n\n def __init__(self, field, ts, te):\n self.field = field\n self.variables = {\n 'ts': ts,\n 'te': te,\n }\n\n def apply(self, query, data):\n query.setdefault(\n 'bool', {}\n ).setdefault(\n 'must', []\n ).append(\n {\n 'range': {\n self.field: {\n 'gte': self.variables['ts'],\n 'lte': self.variables['te'],\n }\n }\n }\n )\n return query\n\nlast_docs.py\n^^^^^^^^^^^^\n\nThis file show how to define a parameterized elasticsearch query using the filters and variables previously defined.\n\n.. code-block:: python\n\n from esqb.query import BaseQuery\n from filters import time_range_filter\n from v import (\n size,\n sort_field,\n sort_order,\n ts,\n te\n )\n\n\n class LastDocs(BaseQuery):\n\n size = size\n sort = [\n {\n sort_field: {\n \"unmapped_type\": \"float\",\n \"missing\": \"_last\",\n \"order\": sort_order\n }\n }\n ]\n\n def __init__(self):\n BaseQuery.__init__(self)\n self.filters = [\n time_range_filter('timestamp', ts, te)\n ]\n\n def result(self, response):\n return [r.get('_source', {}) for r in self.dotget(response, 'hits.hits')]\n\n\n __doc__ = LastDocs().docs(variables)\n\nexample.py\n^^^^^^^^^^\n\nThis file show how to create a complete query ready to be used by elasticsearch.\n\n.. code-block:: python\n\n from last_docs import LastDocs\n\n\n if __name__ == '__main__':\n q = LastDocs().get_es_query(\n {\n 'ts': '1980',\n 'te': '1990',\n 'query_size': 3,\n 'sort_order': 'asc',\n 'sort_field': 'age'\n }\n )\n print(q)\n\nAnd this is the query.\n\n.. code-block:: sh\n\n $> python example.py\n\n {\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"range\": {\n \"timestamp\": {\n \"gte\": \"1980\",\n \"lte\": \"1990\"\n }\n }\n }\n ]\n }\n },\n \"size\": 3,\n \"aggs\": {},\n \"sort\": [\n {\n \"age\": {\n \"unmapped_type\": \"float\",\n \"missing\": \"_last\",\n \"order\": \"asc\"\n }\n }\n ]\n }\n\n\nFeatures\n--------\n\n* TODO\n\nCredits\n---------\n\nThis package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/openshine/python-esqb", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "esqb", "package_url": "https://pypi.org/project/esqb/", "platform": "", "project_url": "https://pypi.org/project/esqb/", "project_urls": { "Homepage": "https://github.com/openshine/python-esqb" }, "release_url": "https://pypi.org/project/esqb/0.1.1/", "requires_dist": null, "requires_python": "", "summary": "A Query Builder to build queries specially suited for ElasticSearch queries", "version": "0.1.1" }, "last_serial": 3868216, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "cea34589e5975a03e88803b6ea919843", "sha256": "b6b03f6bfbe4c83190f5e36ac84dd4c5b6c90f1a23de08293f7bf392714261e9" }, "downloads": -1, "filename": "esqb-0.1.1.tar.gz", "has_sig": false, "md5_digest": "cea34589e5975a03e88803b6ea919843", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23305, "upload_time": "2018-05-16T10:59:28", "url": "https://files.pythonhosted.org/packages/36/e9/a3c0369785f67c081dfa6e17a16a8ca621f9b7ab3564f631ec54a701995c/esqb-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cea34589e5975a03e88803b6ea919843", "sha256": "b6b03f6bfbe4c83190f5e36ac84dd4c5b6c90f1a23de08293f7bf392714261e9" }, "downloads": -1, "filename": "esqb-0.1.1.tar.gz", "has_sig": false, "md5_digest": "cea34589e5975a03e88803b6ea919843", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23305, "upload_time": "2018-05-16T10:59:28", "url": "https://files.pythonhosted.org/packages/36/e9/a3c0369785f67c081dfa6e17a16a8ca621f9b7ab3564f631ec54a701995c/esqb-0.1.1.tar.gz" } ] }