Skip to content

DeprecationWarning: Passing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead. #1971

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

Open
winnie0101 opened this issue Apr 2, 2025 · 3 comments

Comments

@winnie0101
Copy link

When I use Search(index='test').filter('term', test='test').params(opaque_id='test',).execute(), I want to distinguish different search requests.
However, this triggers a DeprecationWarning: Passing transport options in the API method is deprecated. Use 'Elasticsearch.options()' instead.
Is it possible to fix this to avoid the warning?

It's is my package version:

  • elasticsearch: 8.15.1
  • elasticsearch-dsl: 8.15.4
@miguelgrinberg
Copy link
Collaborator

@winnie0101 If you pass an Elasticsearch client instance explicitly to your searches, then you can configure your options as recommended in the deprecation warning.

Here is an example:

client = Elasticsearch(...)
s = Search(
    using=client.options(opaque_id='test'),
    index='test'
)
s = s.filter('term', test='test')

for hit in s.execute():
    # ...

@winnie0101
Copy link
Author

@miguelgrinberg Thanks for the reply!
Yeah, I know that can pass in an Elasticsearch client instance, but most of the time we’re just used to using the default connection (connections.create_connection(...)). So I was wondering — is there any plan to suppress that warning so we can stick with the default connection style?
Or do you generally recommend always passing in a client instance when running into stuff like this?

@miguelgrinberg
Copy link
Collaborator

miguelgrinberg commented Apr 18, 2025

The change that adds the deprecation message that you are seeing was made about 4 years ago and even though I wasn't involved with this project at the time the intention was to drive people away from mixing transport and client related options, in part because there can be naming collisions between them. I guess everything we've done in the past can be revisited or even reverted if warranted, but at this time making changes in this area is not in our plans, and the warning would eventually turn into an error when this feature is finally removed (although I do not know when this will happen).

I should add that it is possible to set up a default connection that includes an opaque id if that is what you need. Something like this:

from elasticsearch.dsl import connections

client = Elasticsearch(...).options(opaque_id='test')
connections.add_connection('default', client)

From this point on, the default connection that you provided will be used.

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

No branches or pull requests

2 participants