Skip to content

Relative Uri building removes path from root #3691

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

Closed
Drongardx opened this issue Apr 23, 2019 · 2 comments
Closed

Relative Uri building removes path from root #3691

Drongardx opened this issue Apr 23, 2019 · 2 comments

Comments

@Drongardx
Copy link

Drongardx commented Apr 23, 2019

NEST/Elasticsearch.Net version:
7.0.0
Elasticsearch version:
7.0.0
Description of the problem including expected versus actual behavior:
We have elasticsearch located not in the root of url but in some folder. Almost real example: http://site.com/elasticsearch/ . When we try to make Search request with ElasticClient we are getting 404 error because somehow library uses absolute url( http://site.com/{index}/_search?... )

Where this problem appers

src/Elasticsearch.Net/Transport/Pipeline/RequestData.cs
line with
public Uri Uri => Node != null ? new Uri(Node.Uri, PathAndQuery) : null;

As per microsoft documentation of new Uri(Uri,string) in Remarks section

Additionally, if the relativeUri begins with a slash, then it will replace any relative part of the baseUri

And so, because SearchDescriptor creates /{index}/_search pattern - it will replace my /elasticsearch/ in Uri. Possible solutions are change of Uri construction or editing of PathAndQuery variable.

Steps to reproduce:

  1. Create Uri with additional path
    var node = new Uri("http://site.com/elasticsearch");
  2. Create Settings
    var settings = new ConnectionSettings(node);
  3. Create ElasticClient
    var client = new ElasticClient(settings);
  4. Make client.Search request
  5. You will get 404 error(well, because of site.com example url, but anyway you will be able to see OriginalExaption details and there will be http://site.com/{index}/_search?... url)

Provide DebugInformation (if relevant):

DebugInformation of ISearchResponse
Invalid NEST response built from a unsuccessful low level call on POST: /myindex/_search?typed_keys=true&ignore_unavailable=true

Audit trail of this API call:

OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 404 from: POST /myindex/_search?typed_keys=true&ignore_unavailable=true. ServerError: Type: Reason: "Not Found"

Request:

{"query":{"bool":{"filter":[{"range":{"create_time":{"gte":"2019-04-22T00:00:00","lt":"2019-04-22T00:01:00"}}}],"must":[{"query_string":{"analyze_wildcard":true,"query":"*"}}]}},"size":5000}

Response:

{"statusCode":404,"error":"Not Found","message":"Not Found"}

OriginalException.DebugInformation (exactly here we can see full generated url)

FailureReason: BadResponse while attempting POST on http://site.com/myindex/_search?typed_keys=true&ignore_unavailable=true

Audit trail of this API call:

OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 404 from: POST /myindex/_search?typed_keys=true&ignore_unavailable=true. ServerError: Type: Reason: "Not Found"

Request:

{"query":{"bool":{"filter":[{"range":{"create_time":{"gte":"2019-04-22T00:00:00","lt":"2019-04-22T00:01:00"}}}],"must":[{"query_string":{"analyze_wildcard":true,"query":"*"}}]}},"size":5000}

Response:

{"statusCode":404,"error":"Not Found","message":"Not Found"}

Exception:

Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 404 from: POST /myindex/_search?typed_keys=true&ignore_unavailable=true. ServerError: Type: Reason: "Not Found"

Edit: Sorry for bad title and formating. This is literally my first report in github.

@Mpdreamz
Copy link
Member

Thank you very much for reporting this! We changed url building in 7.0 alpha but your usecase is definitely one we have to support and always have done in the past.

I'm surprised we did not have a unit test to cover this will look into how this snuck through.

@Mpdreamz Mpdreamz changed the title Uri Relative Uri building removes path from root Apr 25, 2019
russcam added a commit that referenced this issue Apr 29, 2019
This commit updates the API generator to trim the leading forward slashes from all API paths. When the base URI with which the API path will be combined also contains a relative path, the relative path should be respected in the combined URI output.

Fixes #3691
russcam added a commit that referenced this issue Apr 29, 2019
This commit updates the API generator to trim the leading forward slashes from all API paths. When the base URI with which the API path will be combined also contains a relative path, the relative path should be respected in the combined URI output.

Fixes #3691
@russcam
Copy link
Contributor

russcam commented Apr 29, 2019

I've merged in #3700 to address in the next alpha release.

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

3 participants