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

[FEATURE] How can I currently change the default ApiUrls ? #637

Open
ianido opened this issue May 7, 2024 · 9 comments
Open

[FEATURE] How can I currently change the default ApiUrls ? #637

ianido opened this issue May 7, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@ianido
Copy link

ianido commented May 7, 2024

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?

@ianido ianido added enhancement New feature or request untriaged labels May 7, 2024
@dblock
Copy link
Member

dblock commented May 7, 2024

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.

@dblock dblock closed this as completed May 7, 2024
@ianido
Copy link
Author

ianido commented May 7, 2024

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.

@dblock
Copy link
Member

dblock commented May 7, 2024

I’ll reopen the issue. Why do you need to remap the URL?

@dblock dblock reopened this May 7, 2024
@ianido
Copy link
Author

ianido commented May 7, 2024

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

@Xtansia Xtansia removed the untriaged label May 7, 2024
@Xtansia
Copy link
Collaborator

Xtansia commented May 7, 2024

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 { }
                }
            }));

@ianido
Copy link
Author

ianido commented May 7, 2024

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?

@Xtansia
Copy link
Collaborator

Xtansia commented May 7, 2024

@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

@ianido
Copy link
Author

ianido commented May 9, 2024

Great, that is what I needed, thank you so much.

@dblock
Copy link
Member

dblock commented May 9, 2024

@ianido Care to paste your working code here for the next person? Or maybe even a working sample?

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

No branches or pull requests

3 participants