Description
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:
- Create Uri with additional path
var node = new Uri("http://site.com/elasticsearch");
- Create Settings
var settings = new ConnectionSettings(node);
- Create ElasticClient
var client = new ElasticClient(settings);
- Make client.Search request
- 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:
- [1] BadResponse: Node: http://site.com/elasticsearch/ Took: 00:00:14.2378572
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:
- [1] BadResponse: Node: http://site.com/elasticsearch/ Took: 00:00:14.2378572
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.