Skip to content

Relative Uri building removes path from root #3691

Closed
@Drongardx

Description

@Drongardx

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions