Skip to content

Commit c881b0a

Browse files
committed
#fix #645 when using Elasticsearc.Net in conjuction with NEST response classes .ConnectionStatus was null causing .Infer to be null as well breaking several lookups in places where a lambda would be used to describe a propertypath (facets/aggs/others)
1 parent 88d9dbd commit c881b0a

15 files changed

+104
-81
lines changed

src/Elasticsearch.Net/Connection/Transport.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ public ElasticsearchResponse<T> DoRequest<T>(string method, string path, object
161161
var requestState = new TransportRequestState<T>(tracer, method, path, postData, requestParameters);
162162

163163
var result = this.DoRequest<T>(requestState);
164+
var objectNeedsResponseRef = result.Response as IResponseWithRequestInformation;
165+
if (objectNeedsResponseRef != null)
166+
objectNeedsResponseRef.RequestInformation = result;
164167
tracer.SetResult(result);
165168
return result;
166169
}
@@ -292,7 +295,12 @@ public Task<ElasticsearchResponse<T>> DoRequestAsync<T>(string method, string pa
292295
if (t.Exception != null)
293296
tcs.SetException(t.Exception.Flatten());
294297
else
298+
{
299+
var objectNeedsResponseRef = t.Result.Response as IResponseWithRequestInformation;
300+
if (objectNeedsResponseRef != null)
301+
objectNeedsResponseRef.RequestInformation = t.Result;
295302
tcs.SetResult(t.Result);
303+
}
296304

297305
requestState.Tracer.SetResult(t.Result);
298306
return tcs.Task;

src/Elasticsearch.Net/Domain/ElasticsearchResponse.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.CodeDom;
33
using System.Collections.Generic;
44
using System.Configuration;
5-
using System.Diagnostics;
65
using System.Globalization;
76
using System.Linq;
87
using System.Runtime.CompilerServices;
@@ -20,26 +19,6 @@ namespace Elasticsearch.Net
2019
{
2120
//TODO document and possibly rename some of the properties
2221

23-
public interface IElasticsearchResponse
24-
{
25-
bool Success { get; }
26-
bool SuccessOrKnownError { get; }
27-
IConnectionConfigurationValues Settings { get; }
28-
Exception OriginalException { get; }
29-
string RequestMethod { get; }
30-
string RequestUrl { get; }
31-
[DebuggerDisplay("{Request != null ? System.Text.Encoding.UTF8.GetString(Request) : null,nq}")]
32-
byte[] Request { get; }
33-
int? HttpStatusCode { get; }
34-
int NumberOfRetries { get; }
35-
36-
/// <summary>
37-
/// The raw byte response, only set when IncludeRawResponse() is set on Connection configuration
38-
/// </summary>
39-
[DebuggerDisplay("{ResponseRaw != null ? System.Text.Encoding.UTF8.GetString(ResponseRaw) : null,nq}")]
40-
byte[] ResponseRaw { get; }
41-
}
42-
4322
public static class ElasticsearchResponse
4423
{
4524
internal static Task<ElasticsearchResponse<DynamicDictionary>> WrapAsync(Task<ElasticsearchResponse<Dictionary<string, object>>> responseTask)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Diagnostics;
3+
using Elasticsearch.Net.Connection;
4+
5+
namespace Elasticsearch.Net
6+
{
7+
public interface IElasticsearchResponse
8+
{
9+
bool Success { get; }
10+
bool SuccessOrKnownError { get; }
11+
IConnectionConfigurationValues Settings { get; }
12+
Exception OriginalException { get; }
13+
string RequestMethod { get; }
14+
string RequestUrl { get; }
15+
[DebuggerDisplay("{Request != null ? System.Text.Encoding.UTF8.GetString(Request) : null,nq}")]
16+
byte[] Request { get; }
17+
int? HttpStatusCode { get; }
18+
int NumberOfRetries { get; }
19+
20+
/// <summary>
21+
/// The raw byte response, only set when IncludeRawResponse() is set on Connection configuration
22+
/// </summary>
23+
[DebuggerDisplay("{ResponseRaw != null ? System.Text.Encoding.UTF8.GetString(ResponseRaw) : null,nq}")]
24+
byte[] ResponseRaw { get; }
25+
}
26+
27+
public interface IResponseWithRequestInformation
28+
{
29+
IElasticsearchResponse RequestInformation { get; set; }
30+
}
31+
}

src/Elasticsearch.Net/Elasticsearch.Net.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="Connection\IRequestConnectionConfiguration.cs" />
5353
<Compile Include="Connection\TransportRequestState.cs" />
5454
<Compile Include="Domain\BaseRequestParameters.cs" />
55+
<Compile Include="Domain\IElasticsearchResponse.cs" />
5556
<Compile Include="Domain\IHideObjectMembers.cs" />
5657
<Compile Include="Domain\IRequestParameters.cs" />
5758
<Compile Include="Domain\VoidResponse.cs" />

src/Nest/Domain/Responses/BaseResponse.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Nest
88
{
9-
public interface IResponse
9+
public interface IResponse : IResponseWithRequestInformation
1010
{
1111
bool IsValid { get; }
1212
IElasticsearchResponse ConnectionStatus { get; }
@@ -20,7 +20,11 @@ public BaseResponse()
2020
this.IsValid = true;
2121
}
2222
public virtual bool IsValid { get; internal set; }
23-
public IElasticsearchResponse ConnectionStatus { get; internal set; }
23+
24+
IElasticsearchResponse IResponseWithRequestInformation.RequestInformation { get; set; }
25+
26+
public IElasticsearchResponse ConnectionStatus { get { return ((IResponseWithRequestInformation)this).RequestInformation; } }
27+
2428
public ElasticInferrer _infer;
2529

2630
protected IConnectionSettingsValues Settings
@@ -50,5 +54,6 @@ public ElasticInferrer Infer
5054
return this._infer;
5155
}
5256
}
57+
5358
}
5459
}

src/Nest/Domain/Responses/GetMappingResponse.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public GetMappingResponse()
2424

2525
internal GetMappingResponse(IElasticsearchResponse status, GetRootObjectMappingWrapping dict)
2626
{
27-
this.ConnectionStatus = status;
2827
this.IsValid = status.Success && dict != null && dict.Count > 0;
2928
if (!this.IsValid) return;
3029
var firstNode = dict.First();

src/Nest/Domain/Responses/IndexExistsResponse.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class ExistsResponse : BaseResponse, IExistsResponse
1414
{
1515
internal ExistsResponse(IElasticsearchResponse connectionStatus)
1616
{
17-
this.ConnectionStatus = connectionStatus;
1817
this.IsValid =connectionStatus.Success || connectionStatus.HttpStatusCode == 404;
1918
this.Exists = connectionStatus.Success & connectionStatus.HttpStatusCode == 200;
2019
}

src/Nest/ElasticClient-Aliases.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Task<IGetAliasesResponse> GetAliasesAsync(Func<GetAliasesDescriptor, GetA
5656
private GetAliasesResponse DeserializeGetAliasesResponse(IElasticsearchResponse connectionStatus, Stream stream)
5757
{
5858
if (!connectionStatus.Success)
59-
return new GetAliasesResponse() {ConnectionStatus = connectionStatus, IsValid = false};
59+
return new GetAliasesResponse() { IsValid = false};
6060

6161
var dict = this.Serializer.Deserialize<CrazyAliasesResponse>(stream);
6262

@@ -83,7 +83,6 @@ private GetAliasesResponse DeserializeGetAliasesResponse(IElasticsearchResponse
8383

8484
return new GetAliasesResponse()
8585
{
86-
ConnectionStatus = connectionStatus,
8786
IsValid = true,
8887
Indices = d
8988
};

src/Nest/ElasticClient-Search.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public ISearchResponse<TResult> Search<T, TResult>(Func<SearchDescriptor<T>, Sea
3131
));
3232

3333
var status = this.RawDispatch.SearchDispatch<SearchResponse<TResult>>(pathInfo, descriptor);
34-
status.Response.ConnectionStatus = status;
3534
return status.Success ? status.Response : CreateInvalidInstance<SearchResponse<TResult>>(status);
3635
}
3736

@@ -68,12 +67,9 @@ public Task<ISearchResponse<TResult>> SearchAsync<T, TResult>(
6867
.DeserializationState(deserializationState);
6968

7069
return this.RawDispatch.SearchDispatchAsync<SearchResponse<TResult>>(pathInfo, descriptor)
71-
.ContinueWith<ISearchResponse<TResult>>(t => {
72-
t.Result.Response.ConnectionStatus = t.Result;
73-
return t.Result.Success
74-
? t.Result.Response
75-
: CreateInvalidInstance<SearchResponse<TResult>>(t.Result);
76-
});
70+
.ContinueWith<ISearchResponse<TResult>>(t => t.Result.Success
71+
? t.Result.Response
72+
: CreateInvalidInstance<SearchResponse<TResult>>(t.Result));
7773
}
7874

7975
private JsonConverter CreateCovariantSearchSelector<T, TResult>(SearchDescriptor<T> originalSearchDescriptor)

src/Nest/ElasticClient-Template.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,14 @@ private TemplateResponse DeserializeTemplateResponse(
8989
IElasticsearchResponse response,
9090
Stream stream)
9191
{
92-
if (!response.Success) return new TemplateResponse {ConnectionStatus = response, IsValid = false};
92+
if (!response.Success) return new TemplateResponse {IsValid = false};
9393

9494
var dict = this.Serializer.Deserialize<Dictionary<string, TemplateMapping>>(stream);
9595
if (dict.Count == 0)
9696
throw new DslException("Could not deserialize TemplateMapping");
9797

9898
return new TemplateResponse
9999
{
100-
ConnectionStatus = response,
101100
IsValid = true,
102101
Name = dict.First().Key,
103102
TemplateMapping = dict.First().Value

0 commit comments

Comments
 (0)