-
Notifications
You must be signed in to change notification settings - Fork 803
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
Any plans to give an easy way to make DSL compatible with elasticsearch_async #556
Comments
Some thoughts - actually it mighty be possible without breaking api. if there was a way that search/request object won't use client/connection inside it and be operated just for query construction and not execution, then it would be possible to use it with any other client, for example async one. And we could just wrap response from client in the same manner Search object does it. Of course open question is scan and some other features, but it seems to be easier and faster than just forking and reimplementing api in async manner. |
I currently have no plan to implement this purely for time- and expertise- constraints. I would be very happy to help review and merge a solution if someone came up with it. I think it should just be a matter of implementing a subclass of I think the proper way to implement this would be to create 0 - http://elasticsearch-dsl.readthedocs.io/en/latest/api.html#elasticsearch_dsl.Search.response_class |
The compatibility can reach more or less easily. As an example have a look to this MR [1]. As you said the idea is work with an adhoc class for the Maybe the tricky thing here is how to get support for that without replace the Let me think a bit and I will try to come back with a solution. [1] https://github.com/rkern/line_profiler/pull/75/files |
I have a proof of concept that mixes asyncronous and syncronous behaviour using an intermediate def execute(self, ignore_cache=False):
"""
Execute the search and return an instance of ``Response`` wrapping all
the data.
:arg response_class: optional subclass of ``Response`` to use instead.
"""
if ignore_cache or not hasattr(self, '_response'):
es = connections.get_connection(self._using)
response = es.search(
index=self._index,
doc_type=self._doc_type,
body=self.to_dict(),
**self._params
)
if inspect.isawaitable(response):
f = Future()
def _build_response(task):
self._response = self._response_class(
self,
response.result()
)
f.set_result(self._response)
response.add_done_callback(_build_response)
return f
else:
self._response = self._response_class(
self,
response
)
return self._response Leaving aside readability u other stuff this code allows the library to keep the interface without the need of create derivated classes that will be used ad-hoc for asynchronous environments. Then what ? Refine a bit the code and cover all of these places where there is an interaction with the client to test if the object returned is My suggestion here is kept this implementation only for Python 3.5, previous versions since 2.X to 3.4 will work with the regular and synchronous implementation only. It can be achieved with a simple test of the Python version and introducing a And last but not least, I should be able to prepare a proper MR the following days. Cheers, |
@honzakral I have a proposal, follow this link [1]. This commit only enables the support for asynchronous drivers for the Basically, the commit incorporates the following ideas:
Comments will be wellcomed. |
This last commit [1] improves a bit the current implementation, right now there is no need to implement two different versions of each ES-Dsl function that needs to deal with both client implementations. As a result, maintainability becomes easier than before. |
I have a couple of red flags. Not a big deal but they must be resolved. First of all about the helpers, such as About integration tests, first of all, how can I run them? Once say that, will be nice implement a minimum set of integration tests using an asynchronous client which they will cover the interfaces that are compatible with asynchronous clients, explicitly using Any thoughts? |
Closing this as a duplicate of #1355 |
Hi,
I've seen that you have been working on a project [1] to proxy the official client in aims to achieve a pure asynchronous behavior fully compatible with
asyncio
. I was wondering if there is any plan to do the same for the DSL project.Even though is possible to use an asynchronous connection, as the following snippet shows, the principal interface implementation does not allow the developer to use the
await
statement to get the response. The intermediate objectResponse
is not designed to do so.Is there an plan to implement all of this stuff necessary to make the library compatible with asynchronous environments ?
[1] https://github.com/elastic/elasticsearch-py-async
The text was updated successfully, but these errors were encountered: