Skip to content

Commit 4719fe5

Browse files
committed
Merge branch '2.x' into enhancement/2.x-update-by-query
2 parents f8f1eca + b9ac63a commit 4719fe5

File tree

5 files changed

+74
-145
lines changed

5 files changed

+74
-145
lines changed

src/Nest/Indices/AliasManagement/GetAlias/ElasticClient-GetAlias.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public IGetAliasesResponse GetAlias(Func<GetAliasDescriptor, IGetAliasRequest> s
3636
public IGetAliasesResponse GetAlias(IGetAliasRequest request) =>
3737
this.Dispatcher.Dispatch<IGetAliasRequest, GetAliasRequestParameters, GetAliasesResponse>(
3838
request,
39-
DeserializeGetAliasesResponse,
4039
(p, d) => this.LowLevelDispatch.IndicesGetAliasDispatch<GetAliasesResponse>(p)
4140
);
4241

@@ -48,7 +47,6 @@ public Task<IGetAliasesResponse> GetAliasAsync(Func<GetAliasDescriptor, IGetAlia
4847
public Task<IGetAliasesResponse> GetAliasAsync(IGetAliasRequest request) =>
4948
this.Dispatcher.DispatchAsync<IGetAliasRequest, GetAliasRequestParameters, GetAliasesResponse, IGetAliasesResponse>(
5049
request,
51-
DeserializeGetAliasesResponse,
5250
(p, d) => this.LowLevelDispatch.IndicesGetAliasDispatchAsync<GetAliasesResponse>(p)
5351
);
5452
}

src/Nest/Indices/AliasManagement/GetAliases/ElasticClient-GetAliases.cs

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,95 +7,57 @@
77

88
namespace Nest
99
{
10-
using GetAliasesConverter = Func<IApiCallDetails, Stream, GetAliasesResponse>;
11-
using CrazyAliasesResponse = Dictionary<string, Dictionary<string, Dictionary<string, AliasDefinition>>>;
12-
1310
public partial interface IElasticClient
1411
{
1512
/// <summary>
16-
/// The get index alias api allows to filter by alias name and index name. This api redirects to the master and fetches
13+
/// The get index alias api allows to filter by alias name and index name. This api redirects to the master and fetches
1714
/// the requested index aliases, if available. This api only serialises the found index aliases.
1815
/// <para> </para>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html#alias-retrieving
1916
/// </summary>
2017
/// <param name="selector">A descriptor that describes which aliases/indexes we are interested int</param>
21-
[Obsolete("Deprecated since 1.0, will be removed in 3.0. Use GetAlias which accepts multiple aliases and indices")]
18+
[Obsolete("Deprecated since 1.0, will be removed in 5.0. Use GetAlias which accepts multiple aliases and indices")]
2219
IGetAliasesResponse GetAliases(Func<GetAliasesDescriptor, IGetAliasesRequest> selector = null);
2320

2421
/// <inheritdoc/>
25-
[Obsolete("Deprecated since 1.0, will be removed in 3.0. Use GetAlias which accepts multiple aliases and indices")]
22+
[Obsolete("Deprecated since 1.0, will be removed in 5.0. Use GetAlias which accepts multiple aliases and indices")]
2623
IGetAliasesResponse GetAliases(IGetAliasesRequest request);
2724

2825
/// <inheritdoc/>
29-
[Obsolete("Deprecated since 1.0, will be removed in 3.0. Use GetAlias which accepts multiple aliases and indices")]
26+
[Obsolete("Deprecated since 1.0, will be removed in 5.0. Use GetAlias which accepts multiple aliases and indices")]
3027
Task<IGetAliasesResponse> GetAliasesAsync(Func<GetAliasesDescriptor, IGetAliasesRequest> selector = null);
3128

3229
/// <inheritdoc/>
33-
[Obsolete("Deprecated since 1.0, will be removed in 3.0. Use GetAlias which accepts multiple aliases and indices")]
30+
[Obsolete("Deprecated since 1.0, will be removed in 5.0. Use GetAlias which accepts multiple aliases and indices")]
3431
Task<IGetAliasesResponse> GetAliasesAsync(IGetAliasesRequest request);
3532

3633
}
3734

3835
public partial class ElasticClient
3936
{
4037
/// <inheritdoc/>
41-
[Obsolete("Deprecated since 1.0, will be removed in 3.0. Use GetAlias which accepts multiple aliases and indices")]
38+
[Obsolete("Deprecated since 1.0, will be removed in 5.0. Use GetAlias which accepts multiple aliases and indices")]
4239
public IGetAliasesResponse GetAliases(Func<GetAliasesDescriptor, IGetAliasesRequest> selector = null) =>
4340
this.GetAliases(selector.InvokeOrDefault(new GetAliasesDescriptor()));
4441

4542
/// <inheritdoc/>
46-
[Obsolete("Deprecated since 1.0, will be removed in 3.0. Use GetAlias which accepts multiple aliases and indices")]
47-
public IGetAliasesResponse GetAliases(IGetAliasesRequest request) =>
43+
[Obsolete("Deprecated since 1.0, will be removed in 5.0. Use GetAlias which accepts multiple aliases and indices")]
44+
public IGetAliasesResponse GetAliases(IGetAliasesRequest request) =>
4845
this.Dispatcher.Dispatch<IGetAliasesRequest, GetAliasesRequestParameters, GetAliasesResponse>(
4946
request,
50-
new GetAliasesConverter(DeserializeGetAliasesResponse),
5147
(p, d) => this.LowLevelDispatch.IndicesGetAliasesDispatch<GetAliasesResponse>(p)
5248
);
5349

5450
/// <inheritdoc/>
55-
[Obsolete("Deprecated since 1.0, will be removed in 3.0. Use GetAlias which accepts multiple aliases and indices")]
51+
[Obsolete("Deprecated since 1.0, will be removed in 5.0. Use GetAlias which accepts multiple aliases and indices")]
5652
public Task<IGetAliasesResponse> GetAliasesAsync(Func<GetAliasesDescriptor, IGetAliasesRequest> selector = null) =>
5753
this.GetAliasesAsync(selector.InvokeOrDefault(new GetAliasesDescriptor()));
5854

5955
/// <inheritdoc/>
60-
[Obsolete("Deprecated since 1.0, will be removed in 3.0. Use GetAlias which accepts multiple aliases and indices")]
61-
public Task<IGetAliasesResponse> GetAliasesAsync(IGetAliasesRequest request) =>
56+
[Obsolete("Deprecated since 1.0, will be removed in 5.0. Use GetAlias which accepts multiple aliases and indices")]
57+
public Task<IGetAliasesResponse> GetAliasesAsync(IGetAliasesRequest request) =>
6258
this.Dispatcher.DispatchAsync<IGetAliasesRequest, GetAliasesRequestParameters, GetAliasesResponse, IGetAliasesResponse>(
6359
request,
64-
new GetAliasesConverter(DeserializeGetAliasesResponse),
6560
(p, d) => this.LowLevelDispatch.IndicesGetAliasesDispatchAsync<GetAliasesResponse>(p)
6661
);
67-
68-
//TODO map the response properly, remove list flattening
69-
/// <inheritdoc/>
70-
private GetAliasesResponse DeserializeGetAliasesResponse(IApiCallDetails apiCallDetails, Stream stream)
71-
{
72-
if (!apiCallDetails.Success)
73-
return new GetAliasesResponse();
74-
75-
var dict = this.Serializer.Deserialize<CrazyAliasesResponse>(stream);
76-
77-
var d = new Dictionary<string, IList<AliasDefinition>>();
78-
79-
foreach (var kv in dict)
80-
{
81-
var indexDict = kv.Key;
82-
var aliases = new List<AliasDefinition>();
83-
if (kv.Value != null && kv.Value.ContainsKey("aliases"))
84-
{
85-
var aliasDict = kv.Value["aliases"];
86-
if (aliasDict != null)
87-
aliases = aliasDict.Select(kva =>
88-
{
89-
var alias = kva.Value;
90-
alias.Name = kva.Key;
91-
return alias;
92-
}).ToList();
93-
}
94-
95-
d.Add(indexDict, aliases);
96-
}
97-
98-
return new GetAliasesResponse() { Indices = d };
99-
}
10062
}
101-
}
63+
}
Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Newtonsoft.Json;
25

36
namespace Nest
47
{
8+
[JsonConverter(typeof(GetAliasResponseConverter))]
59
public interface IGetAliasesResponse : IResponse
610
{
711
IDictionary<string, IList<AliasDefinition>> Indices { get; }
812
}
913

1014
public class GetAliasesResponse : ResponseBase, IGetAliasesResponse
1115
{
12-
public IDictionary<string, IList<AliasDefinition>> Indices { get; internal set; } = new Dictionary<string, IList<AliasDefinition>>();
16+
public IDictionary<string, IList<AliasDefinition>> Indices { get; internal set; }
1317
}
14-
}
18+
19+
internal class GetAliasResponseConverter : JsonConverter
20+
{
21+
public override bool CanWrite => false;
22+
23+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
24+
{
25+
throw new NotSupportedException();
26+
}
27+
28+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
29+
{
30+
var dict = serializer.Deserialize<Dictionary<string, Dictionary<string, Dictionary<string, AliasDefinition>>>>(reader);
31+
var indices = new Dictionary<string, IList<AliasDefinition>>();
32+
33+
foreach (var kv in dict)
34+
{
35+
var indexDict = kv.Key;
36+
var aliases = new List<AliasDefinition>();
37+
if (kv.Value != null && kv.Value.ContainsKey("aliases"))
38+
{
39+
var aliasDict = kv.Value["aliases"];
40+
if (aliasDict != null)
41+
aliases = aliasDict.Select(kva =>
42+
{
43+
var alias = kva.Value;
44+
alias.Name = kva.Key;
45+
return alias;
46+
}).ToList();
47+
}
48+
49+
indices.Add(indexDict, aliases);
50+
}
51+
52+
return new GetAliasesResponse { Indices = indices };
53+
}
54+
55+
public override bool CanConvert(Type objectType) => true;
56+
}
57+
}

src/Nest/QueryDsl/Specialized/Script/ScriptQueryConverter.cs

Lines changed: 9 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ namespace Nest
88
{
99
internal class ScriptQueryConverter : JsonConverter
1010
{
11-
private readonly VerbatimDictionaryKeysJsonConverter _dictionaryConverter =
12-
new VerbatimDictionaryKeysJsonConverter();
13-
14-
private readonly PropertyJsonConverter _elasticTypeConverter = new PropertyJsonConverter();
15-
1611
public override bool CanRead => true;
1712
public override bool CanWrite => true;
1813
public override bool CanConvert(Type objectType) => true;
@@ -40,7 +35,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
4035

4136
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
4237
{
43-
var r = new ScriptQuery();
38+
var query = new ScriptQuery();
4439
JObject o = JObject.Load(reader);
4540
var properties = o.Properties().ToListOrNullIfEmpty();
4641
var scriptProperty = properties.FirstOrDefault(p => p.Name == "script");
@@ -52,102 +47,29 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
5247
switch (p.Name)
5348
{
5449
case "_name":
55-
r.Name = p.Value.Value<string>();
56-
break;
57-
case "boost":
58-
r.Boost = p.Value.Value<double>();
59-
break;
60-
case "id":
61-
r.Id = p.Value.Value<string>();
62-
break;
63-
case "file":
64-
r.File = p.Value.Value<string>();
65-
break;
66-
case "inline":
67-
r.Inline = p.Value.Value<string>();
68-
break;
69-
case "lang":
70-
r.Lang = p.Value.Value<string>();
71-
break;
72-
case "params":
73-
r.Params = p.Value.ToObject<Dictionary<string, object>>();
74-
break;
75-
}
76-
}
77-
return r;
78-
}
79-
}
80-
81-
82-
83-
internal class SimpleScriptQueryConverter : JsonConverter
84-
{
85-
private readonly VerbatimDictionaryKeysJsonConverter _dictionaryConverter =
86-
new VerbatimDictionaryKeysJsonConverter();
87-
88-
private readonly PropertyJsonConverter _elasticTypeConverter = new PropertyJsonConverter();
89-
90-
public override bool CanRead => true;
91-
public override bool CanWrite => true;
92-
public override bool CanConvert(Type objectType) => true;
93-
94-
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
95-
{
96-
var v = value as IScriptQuery;
97-
if (v == null) return;
98-
99-
writer.WriteStartObject();
100-
if (!v.Name.IsNullOrEmpty()) writer.WriteProperty(serializer, "_name", v.Name);
101-
if (v.Boost != null) writer.WriteProperty(serializer, "boost", v.Boost);
102-
//writer.WritePropertyName("script");
103-
writer.WriteStartObject();
104-
{
105-
if (v.Id != null) writer.WriteProperty(serializer, "id", v.Id);
106-
if (v.File != null) writer.WriteProperty(serializer, "file", v.File);
107-
if (v.Inline != null) writer.WriteProperty(serializer, "inline", v.Inline);
108-
if (v.Lang != null) writer.WriteProperty(serializer, "lang", v.Lang);
109-
if (v.Params != null) writer.WriteProperty(serializer, "params", v.Params);
110-
}
111-
//writer.WriteEndObject();
112-
writer.WriteEndObject();
113-
}
114-
115-
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
116-
{
117-
var r = new ScriptQuery();
118-
JObject o = JObject.Load(reader);
119-
var properties = o.Properties().ToListOrNullIfEmpty();
120-
//var scriptProperty = properties.First(p=>p.Name == "script");
121-
//properties.AddRange(scriptProperty.Value.Value<JObject>().Properties());
122-
123-
foreach (var p in properties)
124-
{
125-
switch (p.Name)
126-
{
127-
case "_name":
128-
r.Name = p.Value.Value<string>();
50+
query.Name = p.Value.Value<string>();
12951
break;
13052
case "boost":
131-
r.Boost = p.Value.Value<double>();
53+
query.Boost = p.Value.Value<double>();
13254
break;
13355
case "id":
134-
r.Id = p.Value.Value<string>();
56+
query.Id = p.Value.Value<string>();
13557
break;
13658
case "file":
137-
r.File = p.Value.Value<string>();
59+
query.File = p.Value.Value<string>();
13860
break;
13961
case "inline":
140-
r.Inline = p.Value.Value<string>();
62+
query.Inline = p.Value.Value<string>();
14163
break;
14264
case "lang":
143-
r.Lang = p.Value.Value<string>();
65+
query.Lang = p.Value.Value<string>();
14466
break;
14567
case "params":
146-
r.Params = p.Value.ToObject<Dictionary<string, object>>();
68+
query.Params = p.Value.ToObject<Dictionary<string, object>>();
14769
break;
14870
}
14971
}
150-
return r;
72+
return query;
15173
}
15274
}
15375
}

src/Tests/Indices/AliasManagement/GetAlias/GetAliasApiTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using Elasticsearch.Net;
45
using FluentAssertions;
56
using Nest;
@@ -11,7 +12,7 @@ namespace Tests.Indices.AliasManagement.GetAlias
1112
{
1213
public class GetAliasApiTests : ApiIntegrationTestBase<ReadOnlyCluster, IGetAliasesResponse, IGetAliasRequest, GetAliasDescriptor, GetAliasRequest>
1314
{
14-
private static readonly Names Names = Infer.Names("alias, x", "y");
15+
private static readonly Names Names = Infer.Names("projects-alias", "alias, x", "y");
1516

1617
public GetAliasApiTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
1718

@@ -25,10 +26,13 @@ protected override LazyResponses ClientUsage() => Calls(
2526
protected override bool ExpectIsValid => true;
2627
protected override int ExpectStatusCode => 200;
2728
protected override HttpMethod HttpMethod => HttpMethod.GET;
28-
protected override string UrlPath => $"/_all/_alias/alias%2Cx%2Cy";
29+
protected override string UrlPath => $"/_all/_alias/projects-alias%2Calias%2Cx%2Cy";
2930
protected override void ExpectResponse(IGetAliasesResponse response)
3031
{
31-
response.Indices.Should().NotBeNull();
32+
response.Indices.Should().NotBeNull().And.ContainKey("project");
33+
var projectIndex = response.Indices["project"];
34+
projectIndex.Should().HaveCount(1);
35+
projectIndex.First().Name.Should().Be("projects-alias");
3236
}
3337
protected override bool SupportsDeserialization => false;
3438

0 commit comments

Comments
 (0)