Skip to content
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

use_dns_cache value cannot be set for AsyncElasticsearch object #2424

Open
qfliu opened this issue Jan 29, 2024 · 3 comments
Open

use_dns_cache value cannot be set for AsyncElasticsearch object #2424

qfliu opened this issue Jan 29, 2024 · 3 comments

Comments

@qfliu
Copy link

qfliu commented Jan 29, 2024

elasticsearch-py version: v7.17.9

Description:
In the old elasticsearch_async library, when creating a AsyncElasticsearch object, we can set value for use_dns_cache to disable dns caching. However, this does not work right now.

Code snippet:

from elasticsearch import AsyncElasticsearch

es_client = AsyncElasticsearch(
    hosts=conf['endpoints'],
    loop=loop,
    timeout=conf.get('request_timeout_seconds'),
    use_dns_cache=False,  # We use ELB to balance the load
)

connection = elastic_client.transport.get_connection()
print(connection.session.connector.use_dns_cache)

I am expecting the output to be False, but it is always True right now.

Am I doing something wrong to set the use_dns_cache value?

@pquentin
Copy link
Member

pquentin commented Feb 2, 2024

Hello! It is indeed not configurable. I'm unlikely to add that feature in the 7.17 client, but could definitely consider it in the 8.x client. Thanks.

@qfliu
Copy link
Author

qfliu commented Feb 12, 2024

Hello! It is indeed not configurable. I'm unlikely to add that feature in the 7.17 client, but could definitely consider it in the 8.x client. Thanks.

Thanks for the reply!

Just to clarify: We have to use dns_cache regardless 7.x or 8.x right now when creating the client. But, can we change it later through another function call by any chance? If not, does that mean we have to use dns_cache all the time right now with es client? Were it every being configurable after making AsyncElasticsearch native instead of using elasticsearch_async lib? Thanks

@pquentin
Copy link
Member

Hey, sorry for missing your reply here. Trying to answer your questions point by point:

  1. I don't know about how it used to work with elasticsearch-async, this was deprecated four years ago now and I never worked on it myself (but I do remember using it!).
  2. We don't currently support changing the internals of the transport. I could teach how to make it work today in 8.13, but it could break in a future release
  3. So yes, the only supported way for now is to use_dns_cache=True all the time. But as you can see in https://docs.aiohttp.org/en/stable/client_advanced.html#tuning-the-dns-cache, the cache is only valid for 10 seconds. How is that a problem for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants