Skip to content

Commit e2e4182

Browse files
committed
Merge branch 'develop' of github.com:elasticsearch/elasticsearch-net into develop
2 parents b46bf09 + 2fec666 commit e2e4182

File tree

16 files changed

+184
-54
lines changed

16 files changed

+184
-54
lines changed

src/Elasticsearch.Net/Domain/Response/ElasticsearchResponse.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Elasticsearch.Net
2323

2424
public static class ElasticsearchResponse
2525
{
26-
internal static Task<ElasticsearchResponse<DynamicDictionary>> WrapAsync(Task<ElasticsearchResponse<Dictionary<string, object>>> responseTask)
26+
public static Task<ElasticsearchResponse<DynamicDictionary>> WrapAsync(Task<ElasticsearchResponse<Dictionary<string, object>>> responseTask)
2727
{
2828
return responseTask
2929
.ContinueWith(t =>
@@ -35,7 +35,7 @@ internal static Task<ElasticsearchResponse<DynamicDictionary>> WrapAsync(Task<El
3535
});
3636
}
3737

38-
internal static ElasticsearchResponse<DynamicDictionary> Wrap(ElasticsearchResponse<Dictionary<string, object>> response)
38+
public static ElasticsearchResponse<DynamicDictionary> Wrap(ElasticsearchResponse<Dictionary<string, object>> response)
3939
{
4040
return ToDynamicResponse(response);
4141
}
@@ -62,7 +62,7 @@ public static ElasticsearchResponse<TTo> CloneFrom<TTo>(IElasticsearchResponse f
6262
return response;
6363
}
6464

65-
private static ElasticsearchResponse<DynamicDictionary> ToDynamicResponse(ElasticsearchResponse<Dictionary<string, object>> response)
65+
public static ElasticsearchResponse<DynamicDictionary> ToDynamicResponse(ElasticsearchResponse<Dictionary<string, object>> response)
6666
{
6767
return CloneFrom(response, response.Response != null ? DynamicDictionary.Create(response.Response) : null);
6868
}
@@ -138,20 +138,20 @@ public bool SuccessOrKnownError
138138
}
139139
}
140140

141-
protected internal ElasticsearchResponse(IConnectionConfigurationValues settings)
141+
public ElasticsearchResponse(IConnectionConfigurationValues settings)
142142
{
143143
this.Settings = settings;
144144
this.Serializer = settings.Serializer;
145145
}
146146

147-
private ElasticsearchResponse(IConnectionConfigurationValues settings, Exception e)
147+
public ElasticsearchResponse(IConnectionConfigurationValues settings, Exception e)
148148
: this(settings)
149149
{
150150
this.Success = false;
151151
this.OriginalException = e;
152152
}
153153

154-
private ElasticsearchResponse(IConnectionConfigurationValues settings, int statusCode)
154+
public ElasticsearchResponse(IConnectionConfigurationValues settings, int statusCode)
155155
: this(settings)
156156
{
157157
this.Success = statusCode >= 200 && statusCode < 300;

src/Elasticsearch.Net/IElasticsearchClient.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public partial interface IElasticsearchClient
2828
/// <param name="data">The body of the request, string and byte[] are posted as is other types will be serialized to JSON</param>
2929
/// <param name="requestParameters">Optionally configure request specific timeouts, headers</param>
3030
/// <returns>A task of ElasticsearchResponse of T where T represents the JSON response body</returns>
31-
Task<ElasticsearchResponse<T>> DoRequestAsync<T>(string method, string path, object data = null, IRequestParameters requestParameters = null);
32-
31+
Task<ElasticsearchResponse<T>> DoRequestAsync<T>(string method, string path, object data = null, IRequestParameters requestParameters = null);
32+
33+
string Encoded(object o);
3334
}
3435
}

src/Nest/DSL/MultiGet/IMultiGetOperation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3+
using Nest.Resolvers.Converters;
34
using Newtonsoft.Json;
45

56
namespace Nest
67
{
78
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
9+
[JsonConverter(typeof(ReadAsTypeConverter<MultiGetOperationDescriptor<object>>))]
810
public interface IMultiGetOperation
911
{
1012
[JsonProperty(PropertyName = "_index")]

src/Nest/DSL/Query/DismaxQueryDescriptor.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,25 @@ public DisMaxQueryDescriptor<T> Queries(params Func<QueryDescriptor<T>, QueryCon
7474
return this;
7575
}
7676

77+
public DisMaxQueryDescriptor<T> Queries(params QueryContainer[] queries)
78+
{
79+
var descriptors = new List<QueryContainer>();
80+
foreach (var q in queries)
81+
{
82+
if (q.IsConditionless)
83+
continue;
84+
descriptors.Add(q);
85+
}
86+
((IDisMaxQuery)this).Queries = descriptors.HasAny() ? descriptors : null;
87+
return this;
88+
}
89+
7790
public DisMaxQueryDescriptor<T> Boost(double boost)
7891
{
7992
Self.Boost = boost;
8093
return this;
8194
}
95+
8296
public DisMaxQueryDescriptor<T> TieBreaker(double tieBreaker)
8397
{
8498
Self.TieBreaker = tieBreaker;

src/Nest/DSL/Query/FunctionScoreQueryDescriptor.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public interface IFunctionScoreQuery : IQuery
1919
[JsonConverter(typeof(CompositeJsonConverter<ReadAsTypeConverter<QueryDescriptor<object>>, CustomJsonConverter>))]
2020
IQueryContainer Query { get; set; }
2121

22+
[JsonProperty(PropertyName = "filter")]
23+
[JsonConverter(typeof(CompositeJsonConverter<ReadAsTypeConverter<FilterContainer>, CustomJsonConverter>))]
24+
IFilterContainer Filter { get; set; }
25+
2226
[JsonProperty(PropertyName = "score_mode")]
2327
[JsonConverter(typeof (StringEnumConverter))]
2428
FunctionScoreMode? ScoreMode { get; set; }
@@ -57,6 +61,7 @@ protected override void WrapInContainer(IQueryContainer container)
5761
public string Name { get; set; }
5862
public IEnumerable<IFunctionScoreFunction> Functions { get; set; }
5963
public IQueryContainer Query { get; set; }
64+
public IFilterContainer Filter { get; set; }
6065
public FunctionScoreMode? ScoreMode { get; set; }
6166
public FunctionBoostMode? BoostMode { get; set; }
6267
public float? MaxBoost { get; set; }
@@ -81,6 +86,8 @@ public class FunctionScoreQueryDescriptor<T> : IFunctionScoreQuery where T : cla
8186

8287
IQueryContainer IFunctionScoreQuery.Query { get; set; }
8388

89+
IFilterContainer IFunctionScoreQuery.Filter { get; set; }
90+
8491
FunctionScoreMode? IFunctionScoreQuery.ScoreMode { get; set; }
8592

8693
FunctionBoostMode? IFunctionScoreQuery.BoostMode { get; set; }
@@ -109,10 +116,9 @@ bool IQuery.IsConditionless
109116
{
110117
get
111118
{
112-
return _forcedConditionless || ((Self.Query == null || Self.Query.IsConditionless)
113-
&& Self.RandomScore == null
114-
&& Self.ScriptScore == null
115-
&& !Self.Functions.HasAny());
119+
return _forcedConditionless
120+
|| ((Self.Query == null || Self.Query.IsConditionless || Self.Filter == null || Self.Filter.IsConditionless)
121+
&& Self.RandomScore == null && Self.ScriptScore == null && !Self.Functions.HasAny());
116122
}
117123
}
118124

@@ -134,10 +140,19 @@ public FunctionScoreQueryDescriptor<T> Query(Func<QueryDescriptor<T>, QueryConta
134140
querySelector.ThrowIfNull("querySelector");
135141
var query = new QueryDescriptor<T>();
136142
var q = querySelector(query);
137-
Self.Query = q.IsConditionless ? null :q;
143+
Self.Query = q.IsConditionless ? null : q;
138144
return this;
139145
}
140146

147+
public FunctionScoreQueryDescriptor<T> Filter(Func<FilterDescriptor<T>, FilterContainer> filterSelector)
148+
{
149+
filterSelector.ThrowIfNull("filterSelector");
150+
var filter = new FilterDescriptor<T>();
151+
var f = filterSelector(filter);
152+
Self.Filter = f.IsConditionless ? null : f;
153+
return this;
154+
}
155+
141156
public FunctionScoreQueryDescriptor<T> Functions(params Func<FunctionScoreFunctionsDescriptor<T>, FunctionScoreFunction<T>>[] functions)
142157
{
143158
var descriptor = new FunctionScoreFunctionsDescriptor<T>();

src/Nest/DSL/Search/SortGeoDistanceDescriptor.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,25 @@ public interface IGeoDistanceSort : ISort, ICustomJson
1515
string PinLocation { get; set; }
1616
IEnumerable<string> Points { get; set; }
1717
GeoUnit? GeoUnit { get; set; }
18+
GeoDistance? DistanceType { get; set; }
1819
}
1920

2021
public class GeoDistanceSort : SortBase, IGeoDistanceSort
2122
{
22-
internal static List<string> Params = new List<string> { "missing", "mode", "order", "unit" };
23+
internal static List<string> Params = new List<string> { "missing", "mode", "order", "unit", "distance_type" };
2324

2425
internal static int MissingIndex = 0;
2526
internal static int ModeIndex = 1;
2627
internal static int OrderIndex = 2;
2728
internal static int UnitIndex = 3;
29+
internal static int DistanceTypeIndex = 4;
2830

2931
public PropertyPathMarker Field { get; set; }
3032
public string PinLocation { get; set; }
3133
public IEnumerable<string> Points { get; set; }
3234
public GeoUnit? GeoUnit { get; set; }
33-
35+
public GeoDistance? DistanceType { get; set; }
36+
3437
object ICustomJson.GetCustomJson()
3538
{
3639
var sort = this.Points.HasAny() ? (object)this.Points : this.PinLocation;
@@ -40,7 +43,8 @@ object ICustomJson.GetCustomJson()
4043
{ Params[MissingIndex], this.Missing },
4144
{ Params[ModeIndex], this.Mode},
4245
{ Params[OrderIndex], this.Order },
43-
{ Params[UnitIndex], this.GeoUnit }
46+
{ Params[UnitIndex], this.GeoUnit },
47+
{ Params[DistanceTypeIndex], this.DistanceType }
4448
};
4549
}
4650
}
@@ -55,7 +59,9 @@ public class SortGeoDistanceDescriptor<T> : SortDescriptorBase<T, SortGeoDistanc
5559
IEnumerable<string> IGeoDistanceSort.Points { get; set; }
5660

5761
GeoUnit? IGeoDistanceSort.GeoUnit { get; set; }
58-
62+
63+
GeoDistance? IGeoDistanceSort.DistanceType { get; set; }
64+
5965
public SortGeoDistanceDescriptor<T> PinTo(string geoLocationHash)
6066
{
6167
geoLocationHash.ThrowIfNullOrEmpty("geoLocationHash");
@@ -93,6 +99,13 @@ public SortGeoDistanceDescriptor<T> Unit(GeoUnit unit)
9399
return this;
94100
}
95101

102+
public SortGeoDistanceDescriptor<T> DistanceType(GeoDistance distanceType)
103+
{
104+
distanceType.ThrowIfNull("distanceType");
105+
Self.DistanceType = distanceType;
106+
return this;
107+
}
108+
96109
public SortGeoDistanceDescriptor<T> OnField(string field)
97110
{
98111
Self.Field = field;
@@ -129,7 +142,8 @@ object ICustomJson.GetCustomJson()
129142
{ GeoDistanceSort.Params[GeoDistanceSort.MissingIndex], Self.Missing },
130143
{ GeoDistanceSort.Params[GeoDistanceSort.ModeIndex], Self.Mode},
131144
{ GeoDistanceSort.Params[GeoDistanceSort.OrderIndex], Self.Order },
132-
{ GeoDistanceSort.Params[GeoDistanceSort.UnitIndex], Self.GeoUnit }
145+
{ GeoDistanceSort.Params[GeoDistanceSort.UnitIndex], Self.GeoUnit },
146+
{ GeoDistanceSort.Params[GeoDistanceSort.DistanceTypeIndex], Self.DistanceType }
133147
};
134148
}
135149
}

src/Nest/Domain/ICustomJson.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ public interface ICustomJson
77
{
88
object GetCustomJson();
99
}
10+
11+
public interface IDomainObject
12+
{
13+
14+
}
1015
}

src/Nest/ElasticClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Nest
1313
/// <summary>
1414
/// ElasticClient is NEST's strongly typed client which exposes fully mapped elasticsearch endpoints
1515
/// </summary>
16-
public partial class ElasticClient : Nest.IElasticClient
16+
public partial class ElasticClient : IElasticClient, IHighLevelToLowLevelDispatcher
1717
{
1818
private readonly IConnectionSettingsValues _connectionSettings;
1919

@@ -57,7 +57,7 @@ public ElasticClient(
5757
}
5858

5959

60-
private R Dispatch<D, Q, R>(
60+
public R Dispatch<D, Q, R>(
6161
Func<D, D> selector
6262
, Func<ElasticsearchPathInfo<Q>, D, ElasticsearchResponse<R>> dispatch
6363
)
@@ -70,7 +70,7 @@ Func<D, D> selector
7070
return this.Dispatch<D, Q, R>(descriptor, dispatch);
7171
}
7272

73-
private R Dispatch<D, Q, R>(
73+
public R Dispatch<D, Q, R>(
7474
D descriptor
7575
, Func<ElasticsearchPathInfo<Q>, D, ElasticsearchResponse<R>> dispatch
7676
)
@@ -111,7 +111,7 @@ private static R CreateInvalidInstance<R>(IElasticsearchResponse response) where
111111
return r;
112112
}
113113

114-
private Task<I> DispatchAsync<D, Q, R, I>(
114+
public Task<I> DispatchAsync<D, Q, R, I>(
115115
Func<D, D> selector
116116
, Func<ElasticsearchPathInfo<Q>, D, Task<ElasticsearchResponse<R>>> dispatch
117117
)
@@ -125,7 +125,7 @@ Func<D, D> selector
125125
return this.DispatchAsync<D, Q, R, I>(descriptor, dispatch);
126126
}
127127

128-
private Task<I> DispatchAsync<D, Q, R, I>(
128+
public Task<I> DispatchAsync<D, Q, R, I>(
129129
D descriptor
130130
, Func<ElasticsearchPathInfo<Q>, D, Task<ElasticsearchResponse<R>>> dispatch
131131
)

src/Nest/ExposedInternals/NestSerializer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public virtual T Deserialize<T>(Stream stream)
8585
return DeserializeUsingSettings<T>(stream, settings);
8686
}
8787

88-
89-
9088
/// <summary>
9189
/// Deserialize to type T bypassing checks for custom deserialization state and or BaseResponse return types.
9290
/// </summary>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Elasticsearch.Net;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Nest
9+
{
10+
public interface IHighLevelToLowLevelDispatcher
11+
{
12+
R Dispatch<D, Q, R>(D descriptor, Func<ElasticsearchPathInfo<Q>, D, ElasticsearchResponse<R>> dispatch)
13+
where Q : FluentRequestParameters<Q>, new()
14+
where D : IRequest<Q>
15+
where R : BaseResponse;
16+
17+
R Dispatch<D, Q, R>(Func<D, D> selector, Func<ElasticsearchPathInfo<Q>, D, ElasticsearchResponse<R>> dispatch)
18+
where Q : FluentRequestParameters<Q>, new()
19+
where D : IRequest<Q>, new()
20+
where R : BaseResponse;
21+
22+
Task<I> DispatchAsync<D, Q, R, I>(D descriptor, Func<ElasticsearchPathInfo<Q>, D, Task<ElasticsearchResponse<R>>> dispatch)
23+
where Q : FluentRequestParameters<Q>, new()
24+
where D : IRequest<Q>
25+
where R : BaseResponse, I
26+
where I : IResponse;
27+
28+
Task<I> DispatchAsync<D, Q, R, I>(Func<D, D> selector, Func<ElasticsearchPathInfo<Q>, D, Task<ElasticsearchResponse<R>>> dispatch)
29+
where Q : FluentRequestParameters<Q>, new()
30+
where D : IRequest<Q>, new()
31+
where R : BaseResponse, I
32+
where I : IResponse;
33+
}
34+
}

0 commit comments

Comments
 (0)