Skip to content

Property OnRequestDataCreated is missing from ElasticsearchClientSettings #8525

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
mathiasaap opened this issue May 15, 2025 · 4 comments
Open
Labels

Comments

@mathiasaap
Copy link

Elastic.Clients.Elasticsearch version: 8.18.0

Elasticsearch version: 8.18.1

.NET runtime version: 8

Description of the problem including expected versus actual behavior:

The property OnRequestDataCreated is missing from the class ElasticsearchClientSettings, but should be available according to the documentation: https://www.elastic.co/docs/reference/elasticsearch/clients/dotnet/_options_on_elasticsearchclientsettings

Steps to reproduce:
This following code should compile, but does not because OnRequestDataCreated does not exist

new ElasticsearchClientSettings().OnRequestDataCreated(request =>
{
    // Do something with the request
});
@mathiasaap mathiasaap added 8.x Relates to a 8.x client version Category: Bug labels May 15, 2025
@flobernd
Copy link
Member

Hi @mathiasaap , this callback does not seem to exist in the 8.x branch and should be removed from the documentation.

Is there anything specific you want to achieve? Happy to help finding an alternative solution.

@mathiasaap
Copy link
Author

Hey @flobernd , thanks for following up

We’re using JWT authentication, but also need to include an ES-Client-Authentication header with a pre-shared secret for each request. We don’t want to set this value using GlobalHeaders, since that would require recreating the Elastic client whenever the secret rotates. Instead, we’d like to add the header dynamically to every request.

OnRequestDataCreated seems like a good fit for this. Is there a simpler or more standard way to achieve dynamic per-request headers, without having to implement and maintain a custom IRequestInvoker or HttpMessageHandler?

@flobernd
Copy link
Member

Hi @mathiasaap , would it work for you to set this header as part of the request?

await client.SearchAsync<Person>(x => x
    .Query(...)
    .RequestConfiguration(x => x.GlobalHeaders(/* these headers are actually local / per-request, and not global */)));

Instead of a descriptor, new RequestConfiguration(...) could be used to create a new global instance as soon as the secret rotates. This instance can be passed to .RequestConfiguration() instead of using the fluent syntax.

I will check if we can re-introduce something like the OnRequestDataCreated callback, when I have some time. The architecture changed quite a bit in the meantime.

@mathiasaap
Copy link
Author

Thanks for the suggestion. While this approach works technically, it introduces awkwardness by mixing setup and usage concerns. We’ll implement a workaround for now, but having something like an OnRequestDataCreated hook would greatly improve the ability to centralize configuration.

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

No branches or pull requests

2 participants