Open ianido opened 6 months ago
There's an example of customizing an URL in https://github.com/opensearch-project/opensearch-net/blob/main/USER_GUIDE.md#connecting-1, please let us know if that's not sufficient?
For faster response, a better place to ask questions is the public slack #client channel.
I do can change with the ConnectionSettings the server base url but I couln't find a way to customize the URL path for search; or any operation in general; for example:
var config = new ConnectionSettings(new Uri("{baseaddress}"));
config.ApiKeyAuthentication("...", "...");
OpenSearchClient client = new OpenSearchClient(config);
var searchResponse = client.Search<LoanProCustomersModel>(s => s
.Index("Customers")
.Query(q => q
.Match(m => m
.Field(fld => fld.lastName)
.Query("Dorantes Ostria"))));
The Search url will be
{baseaddress}/Customers/_search
and it needed to be
{baseaddress}/Customers/Search
I am looking a way to do an interceptor or a DelegatingHandler to change or remap the URL but I dont find a way.
The reason of this feature is because we have an OpenSearch service provider that customized their urls.
I’ll reopen the issue. Why do you need to remap the URL?
We have this service provider who recently migrated from ElasticSearch to OpenSearch and they will maintain their previous URLs to keep compatibility as much as possible:
https://developers.loanpro.io/docs/opensearch-migration
So for example when we search by Customers; we need to send the POST to:
https://loanpro.simnang.com/api/public/api/1/tmp/{resource}/search
this is different from the standard search endpoint "{index}/_search" that will result in:
https://loanpro.simnang.com/api/public/api/1/tmp/{resource}/_search
The only real way to achieve this with the client is to use the raw HTTP request API, e.g.:
var searchResp = await client.Http.PostAsync<SearchResponse<TheDocument>>(
$"/{resource}/search",
r => r.SerializableBody(new
{
query = new
{
match_all = new { }
}
}));
We are currently start working in this way, but definetely having support to customize the apiUrls in the High Level version of the library would be a great value, is there any way to attach a delegating handler to the HttpClient used internally?
@ianido You could try doing something similar to how AWS SigV4 signing is implemented, extending from HttpConnection
and then overriding CreateHttpClientHandler
to return your delegating handler:
You then pass it into ConnectionSettings
like so: https://github.com/opensearch-project/opensearch-net/blob/main/USER_GUIDE.md#connecting-1
Great, that is what I needed, thank you so much.
@ianido Care to paste your working code here for the next person? Or maybe even a working sample?
I have to connect to a deployed instance of opensearch with different Urls, for example a regular {indexname}/_search is {indexname}search, similar with other features, how can I change this confguration in the Client?