Skip to content

Commit 8b5fa41

Browse files
Documentation updates
1 parent 7386dd5 commit 8b5fa41

File tree

4 files changed

+142
-7
lines changed

4 files changed

+142
-7
lines changed

Diff for: CONTRIBUTING.rst

+15-4
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,33 @@ The process for contributing to any of the Elasticsearch repositories is similar
2525
assure our users of the origin and continuing existence of the code. You only
2626
need to sign the CLA once.
2727

28-
2. Run the test suite to ensure your changes do not break existing code:
28+
2. Many classes included in this library are offered in two versions, for
29+
asynchronous and synchronous Python. When working with these classes, you only
30+
need to make changes to the asynchronous code, located in the *_async*
31+
subdirectory of the source tree. Once you've made your changes, run the
32+
following command to automatically generate the corresponding synchronous code:
33+
34+
.. code:: bash
35+
36+
$ nox -rs format
37+
38+
3. Run the test suite to ensure your changes do not break existing code:
2939

3040
.. code:: bash
3141
3242
$ nox -rs lint test
3343
34-
3. Rebase your changes.
44+
4. Rebase your changes.
3545
Update your local repository with the most recent code from the main
3646
elasticsearch-dsl-py repository, and rebase your branch on top of the latest master
3747
branch. We prefer your changes to be squashed into a single commit.
3848

39-
4. Submit a pull request. Push your local changes to your forked copy of the
49+
5. Submit a pull request. Push your local changes to your forked copy of the
4050
repository and submit a pull request. In the pull request, describe what your
4151
changes do and mention the number of the issue where discussion has taken
4252
place, eg “Closes #123″. Please consider adding or modifying tests related to
43-
your changes.
53+
your changes. Include any generated files in the *_sync* subdirectory in your
54+
pull request.
4455

4556
Then sit back and wait. There will probably be discussion about the pull
4657
request and, if any changes are needed, we would love to work with you to get

Diff for: docs/api.rst

+34-3
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,70 @@ Search
1111
------
1212

1313
.. autoclass:: Search
14+
:inherited-members:
1415
:members:
1516

1617
.. autoclass:: MultiSearch
18+
:inherited-members:
19+
:members:
20+
21+
.. autoclass:: AsyncSearch
22+
:inherited-members:
23+
:members:
24+
25+
.. autoclass:: AsyncMultiSearch
26+
:inherited-members:
1727
:members:
1828

1929
Document
2030
--------
2131

2232
.. autoclass:: Document
33+
:inherited-members:
34+
:members:
35+
36+
.. autoclass:: AsyncDocument
37+
:inherited-members:
2338
:members:
2439

2540
Index
2641
-----
2742

2843
.. autoclass:: Index
44+
:inherited-members:
45+
:members:
46+
47+
.. autoclass:: AsyncIndex
48+
:inherited-members:
2949
:members:
3050

3151
Faceted Search
3252
--------------
3353

3454
.. autoclass:: FacetedSearch
55+
:inherited-members:
56+
:members:
57+
58+
.. autoclass:: AsyncFacetedSearch
59+
:inherited-members:
3560
:members:
3661

3762
Update By Query
3863
----------------
64+
3965
.. autoclass:: UpdateByQuery
40-
:members:
66+
:inherited-members:
67+
:members:
68+
69+
.. autoclass:: AsyncUpdateByQuery
70+
:inherited-members:
71+
:members:
4172

4273
Mappings
4374
--------
4475

45-
If you wish to create mappings manually you can use the ``Mapping`` class, for
46-
more advanced use cases, however, we recommend you use the :ref:`doc_type`
76+
If you wish to create mappings manually you can use the ``Mapping`` or ``AsyncMapping``
77+
classes, for more advanced use cases, however, we recommend you use the :ref:`doc_type`
4778
abstraction in combination with :ref:`index` (or :ref:`index-template`) to define
4879
index-level settings and properties. The mapping definition follows a similar
4980
pattern to the query dsl:

Diff for: docs/asyncio.rst

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
.. _asyncio:
2+
3+
Using Asyncio with Elasticsearch DSL
4+
====================================
5+
6+
The ``elasticsearch-dsl`` package supports async/await with `Asyncio <https://docs.python.org/3/library/asyncio.html>`__.
7+
To ensure that you have all the required dependencies, install the ``[async]`` extra:
8+
9+
.. code:: bash
10+
11+
$ python -m pip install elasticsearch-dsl[async]
12+
13+
Connections
14+
-----------
15+
16+
Use the ``async_connections`` module to manage your asynchronous connections.
17+
18+
.. code:: python
19+
20+
from elasticsearch_dsl import async_connections
21+
22+
async_connections.create_connection(hosts=['localhost'], timeout=20)
23+
24+
All the options available in the ``connections`` module can be used with ``async_connections``.
25+
26+
How to avoid 'Unclosed client session / connector' warnings on exit
27+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28+
29+
These warnings come from the ``aiohttp`` package, which is used internally by the
30+
``AsyncElasticsearch`` client. They appear often when the application exits and
31+
are caused by HTTP connections that are open when they are garbage collected. To
32+
avoid these warnings, make sure that you close your connections.
33+
34+
.. code:: python
35+
36+
es = async_connections.get_connection()
37+
await es.close()
38+
39+
Search DSL
40+
----------
41+
42+
Use the ``AsyncSearch`` class to perform asynchronous searches.
43+
44+
.. code:: python
45+
46+
from elasticsearch_dsl import AsyncSearch
47+
48+
s = AsyncSearch().query("match", title="python")
49+
async for hit in s:
50+
print(hit.title)
51+
52+
Instead of using the ``AsyncSearch`` object as an asynchronous iterator, you can
53+
explicitly call the ``execute()`` method to get a ``Response`` object.
54+
55+
.. code:: python
56+
57+
s = AsyncSearch().query("match", title="python")
58+
response = await s.execute()
59+
for hit in response:
60+
print(hit.title)
61+
62+
An ``AsyncMultiSearch`` is available as well.
63+
64+
.. code:: python
65+
66+
from elasticsearch_dsl import AsyncMultiSearch
67+
68+
ms = AsyncMultiSearch(index='blogs')
69+
70+
ms = ms.add(AsyncSearch().filter('term', tags='python'))
71+
ms = ms.add(AsyncSearch().filter('term', tags='elasticsearch'))
72+
73+
responses = await ms.execute()
74+
75+
for response in responses:
76+
print("Results for query %r." % response.search.query)
77+
for hit in response:
78+
print(hit.title)
79+
80+
Asynchronous Documents, Indexes, and more
81+
-----------------------------------------
82+
83+
The ``Document``, ``Index``, ``IndexTemplate``, ``Mapping``, ``UpdateByQuery`` and
84+
``FacetedSearch`` classes all have asynchronous versions that use the same name
85+
with an ``Async`` prefix. These classes expose the same interfaces as the
86+
synchronous versions, but any methods that perform I/O are defined as coroutines.
87+
88+
Auxiliary classes that do not perform I/O do not have asynchronous versions. The
89+
same classes can be used in synchronous and asynchronous applications.
90+
91+
You can consult the :ref:`api` section for details about each specific
92+
method.

Diff for: docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ Contents
351351
persistence
352352
faceted_search
353353
update_by_query
354+
asyncio
354355
api
355356
CONTRIBUTING
356357
Changelog

0 commit comments

Comments
 (0)