Skip to content

Add Async I/O Support #1435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
30 changes: 30 additions & 0 deletions elasticsearch_dsl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

import sys

from . import connections
from .aggs import A
from .analysis import analyzer, char_filter, normalizer, token_filter, tokenizer
Expand Down Expand Up @@ -159,3 +161,31 @@
"token_filter",
"tokenizer",
]


try:
# Asyncio only supported in Python 3.6+
if sys.version_info < (3, 6):
raise ImportError

from elasticsearch_dsl._async.faceted_search import AsyncFacetedSearch
from elasticsearch_dsl._async.index import AsyncIndex, AsyncIndexTemplate
from elasticsearch_dsl._async.mapping import AsyncMapping
from elasticsearch_dsl._async.search import AsyncMultiSearch, AsyncSearch
from elasticsearch_dsl._async.update_by_query import AsyncUpdateByQuery

__all__ = sorted(
__all__
+ [
"AsyncFacetedSearch",
"AsyncIndex",
"AsyncIndexTemplate",
"AsyncMapping",
"AsyncMultiSearch",
"AsyncSearch",
"AsyncUpdateByQuery",
]
)

except (ImportError, SyntaxError):
pass
11 changes: 11 additions & 0 deletions elasticsearch_dsl/_async/faceted_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from elasticsearch_dsl.faceted_search import FacetedSearch


class AsyncFacetedSearch(FacetedSearch):
async def execute(self):
"""
Asynchronously execute the search and return the response.
"""
r = await self._s.execute()
r._faceted_search = self
return r
Loading