{ "info": { "author": "Honza Kr\u00e1l", "author_email": "honza.kral@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "Elasticsearch DSL\n=================\n\nElasticsearch DSL is a high-level library whose aim is to help with writing and\nrunning queries against Elasticsearch. It is built on top of the official\nlow-level client (``elasticsearch-py``).\n\nIt provides a more convenient and idiomatic way to write and manipulate\nqueries. It stays close to the Elasticsearch JSON DSL, mirroring its\nterminology and structure. It exposes the whole range of the DSL from Python\neither directly using defined classes or a queryset-like expressions.\n\nIt also provides an optional wrapper for working with documents as Python\nobjects: defining mappings, retrieving and saving documents, wrapping the\ndocument data in user-defined classes.\n\nTo use the other Elasticsearch APIs (eg. cluster health) just use the\nunderlying client.\n\nCompatibility\n-------------\n\nThe library is compatible with all Elasticsearch versions since ``1.x`` but you\n**have to use a matching major version**:\n\nFor **Elasticsearch 2.0** and later, use the major version 2 (``2.x.y``) of the\nlibrary.\n\nFor **Elasticsearch 1.0** and later, use the major version 0 (``0.x.y``) of the\nlibrary.\n\n\nThe recommended way to set your requirements in your `setup.py` or\n`requirements.txt` is::\n\n # Elasticsearch 2.x\n elasticsearch-dsl>=2.0.0,<3.0.0\n\n # Elasticsearch 1.x\n elasticsearch-dsl<2.0.0\n\n\nThe development is happening on ``master`` and ``1.x`` branches, respectively.\n\nSearch Example\n--------------\n\nLet's have a typical search request written directly as a ``dict``:\n\n.. code:: python\n\n from elasticsearch1 import Elasticsearch\n client = Elasticsearch()\n\n response = client.search(\n index=\"my-index\",\n body={\n \"query\": {\n \"filtered\": {\n \"query\": {\n \"bool\": {\n \"must\": [{\"match\": {\"title\": \"python\"}}],\n \"must_not\": [{\"match\": {\"description\": \"beta\"}}]\n }\n },\n \"filter\": {\"term\": {\"category\": \"search\"}}\n }\n },\n \"aggs\" : {\n \"per_tag\": {\n \"terms\": {\"field\": \"tags\"},\n \"aggs\": {\n \"max_lines\": {\"max\": {\"field\": \"lines\"}}\n }\n }\n }\n }\n )\n\n for hit in response['hits']['hits']:\n print(hit['_score'], hit['_source']['title'])\n\n for tag in response['aggregations']['per_tag']['buckets']:\n print(tag['key'], tag['max_lines']['value'])\n\n\n\nThe problem with this approach is that it is very verbose, prone to syntax\nmistakes like incorrect nesting, hard to modify (eg. adding another filter) and\ndefinitely not fun to write.\n\nLet's rewrite the example using the Python DSL:\n\n.. code:: python\n\n from elasticsearch1 import Elasticsearch\n from elasticsearch1_dsl import Search, Q\n\n client = Elasticsearch()\n\n s = Search(using=client, index=\"my-index\") \\\n .filter(\"term\", category=\"search\") \\\n .query(\"match\", title=\"python\") \\\n .query(~Q(\"match\", description=\"beta\"))\n\n s.aggs.bucket('per_tag', 'terms', field='tags') \\\n .metric('max_lines', 'max', field='lines')\n\n response = s.execute()\n\n for hit in response:\n print(hit.meta.score, hit.title)\n\n for tag in response.aggregations.per_tag.buckets:\n print(tag.key, tag.max_lines.value)\n\nAs you see, the library took care of:\n\n * creating appropriate ``Query`` objects by name (eq. \"match\")\n\n * composing queries into a compound ``bool`` query\n\n * creating a ``filtered`` query since ``.filter()`` was used\n\n * providing a convenient access to response data\n\n * no curly or square brackets everywhere\n\n\nPersistence Example\n-------------------\n\nLet's have a simple Python class representing an article in a blogging system:\n\n.. code:: python\n\n from datetime import datetime\n from elasticsearch1_dsl import DocType, String, Date, Integer\n from elasticsearch1_dsl.connections import connections\n\n # Define a default Elasticsearch client\n connections.create_connection(hosts=['localhost'])\n\n class Article(DocType):\n title = String(analyzer='snowball', fields={'raw': String(index='not_analyzed')})\n body = String(analyzer='snowball')\n tags = String(index='not_analyzed')\n published_from = Date()\n lines = Integer()\n\n class Meta:\n index = 'blog'\n\n def save(self, ** kwargs):\n self.lines = len(self.body.split())\n return super(Article, self).save(** kwargs)\n\n def is_published(self):\n return datetime.now() > self.published_from\n\n # create the mappings in elasticsearch\n Article.init()\n\n # create and save and article\n article = Article(meta={'id': 42}, title='Hello world!', tags=['test'])\n article.body = ''' looong text '''\n article.published_from = datetime.now()\n article.save()\n\n article = Article.get(id=42)\n print(article.is_published())\n\n # Display cluster health\n print(connections.get_connection().cluster.health())\n\n\nIn this example you can see:\n\n * providing a default connection\n\n * defining fields with mapping configuration\n\n * setting index name\n\n * defining custom methods\n\n * overriding the built-in ``.save()`` method to hook into the persistence\n life cycle\n\n * retrieving and saving the object into Elasticsearch\n\n * accessing the underlying client for other APIs\n\nYou can see more in the persistence chapter of the documentation.\n\nMigration from ``elasticsearch-py``\n-----------------------------------\n\nYou don't have to port your entire application to get the benefits of the\nPython DSL, you can start gradually by creating a ``Search`` object from your\nexisting ``dict``, modifying it using the API and serializing it back to a\n``dict``:\n\n.. code:: python\n\n body = {...} # insert complicated query here\n\n # Convert to Search object\n s = Search.from_dict(body)\n\n # Add some filters, aggregations, queries, ...\n s.filter(\"term\", tags=\"python\")\n\n # Convert back to dict to plug back into existing code\n body = s.to_dict()\n\nDocumentation\n-------------\n\nDocumentation is available at https://elasticsearch-dsl.readthedocs.org.\n\nLicense\n-------\n\nCopyright 2013 Elasticsearch\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/elasticsearch/elasticsearch-dsl-py", "keywords": null, "license": "Apache License, Version 2.0", "maintainer": null, "maintainer_email": null, "name": "elasticsearch1-dsl", "package_url": "https://pypi.org/project/elasticsearch1-dsl/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/elasticsearch1-dsl/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/elasticsearch/elasticsearch-dsl-py" }, "release_url": "https://pypi.org/project/elasticsearch1-dsl/0.0.12/", "requires_dist": null, "requires_python": null, "summary": "Python client for Elasticsearch1", "version": "0.0.12" }, "last_serial": 2254530, "releases": { "0.0.12": [ { "comment_text": "", "digests": { "md5": "b7c738ee6465113ab07710da8eabf6a4", "sha256": "58c208c602041baba1c55a123e9d6e7f4b2b9912d417545b433b02e312ba97c1" }, "downloads": -1, "filename": "elasticsearch1_dsl-0.0.12-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b7c738ee6465113ab07710da8eabf6a4", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 39816, "upload_time": "2016-08-01T02:35:35", "url": "https://files.pythonhosted.org/packages/11/bd/fbf94dc56dc9127f508c1b617351576a9caaff46a460547940c5edaa21e9/elasticsearch1_dsl-0.0.12-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7c8a2f5342a8eb71386d8d231d877ec3", "sha256": "132e31cebdba58769ec814ebc00d4742f25f17b4bc9cf4815a70a49d86a7e145" }, "downloads": -1, "filename": "elasticsearch1-dsl-0.0.12.tar.gz", "has_sig": false, "md5_digest": "7c8a2f5342a8eb71386d8d231d877ec3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29408, "upload_time": "2016-08-01T02:35:24", "url": "https://files.pythonhosted.org/packages/eb/9d/785342775cb10eddc9b8d7457d618a423b4f0b89d8b2b2d1bc27190d71db/elasticsearch1-dsl-0.0.12.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b7c738ee6465113ab07710da8eabf6a4", "sha256": "58c208c602041baba1c55a123e9d6e7f4b2b9912d417545b433b02e312ba97c1" }, "downloads": -1, "filename": "elasticsearch1_dsl-0.0.12-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "b7c738ee6465113ab07710da8eabf6a4", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 39816, "upload_time": "2016-08-01T02:35:35", "url": "https://files.pythonhosted.org/packages/11/bd/fbf94dc56dc9127f508c1b617351576a9caaff46a460547940c5edaa21e9/elasticsearch1_dsl-0.0.12-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7c8a2f5342a8eb71386d8d231d877ec3", "sha256": "132e31cebdba58769ec814ebc00d4742f25f17b4bc9cf4815a70a49d86a7e145" }, "downloads": -1, "filename": "elasticsearch1-dsl-0.0.12.tar.gz", "has_sig": false, "md5_digest": "7c8a2f5342a8eb71386d8d231d877ec3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 29408, "upload_time": "2016-08-01T02:35:24", "url": "https://files.pythonhosted.org/packages/eb/9d/785342775cb10eddc9b8d7457d618a423b4f0b89d8b2b2d1bc27190d71db/elasticsearch1-dsl-0.0.12.tar.gz" } ] }