Skip to content

Commit 03e89e9

Browse files
stevejgordongithub-actions[bot]
authored andcommitted
Add rollover API support for max_primary_shard_size (#5353)
1 parent e4a4aef commit 03e89e9

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed

src/Nest/Indices/IndexManagement/RolloverIndex/RolloverConditions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public interface IRolloverConditions
3535
/// </remarks>
3636
[DataMember(Name ="max_size")]
3737
string MaxSize { get; set; }
38+
39+
/// <summary>
40+
/// The maximum size of the primary shards in the index e.g. "2gb"
41+
/// </summary>
42+
/// <remarks>
43+
/// Valid in Elasticsearch 7.12.0+
44+
/// </remarks>
45+
[DataMember(Name = "max_primary_shard_size")]
46+
string MaxPrimaryShardSize { get; set; }
3847
}
3948

4049
/// <inheritdoc />
@@ -48,6 +57,9 @@ public class RolloverConditions : IRolloverConditions
4857

4958
/// <inheritdoc />
5059
public string MaxSize { get; set; }
60+
61+
/// <inheritdoc />
62+
public string MaxPrimaryShardSize { get; set; }
5163
}
5264

5365
/// <inheritdoc cref="IRolloverConditions" />
@@ -57,6 +69,7 @@ public class RolloverConditionsDescriptor
5769
Time IRolloverConditions.MaxAge { get; set; }
5870
long? IRolloverConditions.MaxDocs { get; set; }
5971
string IRolloverConditions.MaxSize { get; set; }
72+
string IRolloverConditions.MaxPrimaryShardSize { get; set; }
6073

6174
/// <inheritdoc cref="IRolloverConditions.MaxAge" />
6275
public RolloverConditionsDescriptor MaxAge(Time maxAge) => Assign(maxAge, (a, v) => a.MaxAge = v);
@@ -66,5 +79,8 @@ public class RolloverConditionsDescriptor
6679

6780
/// <inheritdoc cref="IRolloverConditions.MaxSize" />
6881
public RolloverConditionsDescriptor MaxSize(string maxSize) => Assign(maxSize, (a, v) => a.MaxSize = v);
82+
83+
/// <inheritdoc cref="IRolloverConditions.MaxPrimaryShardSize" />
84+
public RolloverConditionsDescriptor MaxPrimaryShardSize(string maxPrimaryShardSize) => Assign(maxPrimaryShardSize, (a, v) => a.MaxPrimaryShardSize = v);
6985
}
7086
}

tests/Tests/Indices/IndexManagement/RolloverIndex/RolloverIndexApiTests.cs

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using Elastic.Elasticsearch.Xunit.XunitPlumbing;
78
using Elasticsearch.Net;
89
using FluentAssertions;
910
using Nest;
@@ -166,4 +167,165 @@ protected override void ExpectResponse(RolloverIndexResponse response)
166167
response.Conditions["[max_docs: 1000]"].Should().BeTrue();
167168
}
168169
}
170+
171+
[SkipVersion("<7.12.0", "Tests all parameters available in 7.12.0 and higher")]
172+
public class RolloverIndexApiWithAllParametersTests
173+
: ApiIntegrationTestBase<WritableCluster, RolloverIndexResponse, IRolloverIndexRequest, RolloverIndexDescriptor, RolloverIndexRequest>
174+
{
175+
public RolloverIndexApiWithAllParametersTests(WritableCluster cluster, EndpointUsage usage)
176+
: base(cluster, usage) { }
177+
178+
protected override bool ExpectIsValid => true;
179+
protected override int ExpectStatusCode => 200;
180+
protected override HttpMethod HttpMethod => HttpMethod.POST;
181+
protected override bool SupportsDeserialization => false;
182+
protected override string UrlPath => $"/{CallIsolatedValue}-alias/_rollover/{CallIsolatedValue}-new";
183+
184+
protected override object ExpectJson => new
185+
{
186+
conditions = new
187+
{
188+
max_age = "7d",
189+
max_docs = 1000,
190+
max_size = "5gb",
191+
max_primary_shard_size = "2gb"
192+
},
193+
settings = new Dictionary<string, object>
194+
{
195+
{ "index.number_of_shards", 1 },
196+
{ "index.number_of_replicas", 1 }
197+
},
198+
mappings = new
199+
{
200+
properties = new
201+
{
202+
branches = new
203+
{
204+
type = "text",
205+
fields = new
206+
{
207+
keyword = new
208+
{
209+
type = "keyword",
210+
ignore_above = 256
211+
}
212+
}
213+
}
214+
}
215+
},
216+
aliases = new Dictionary<string, object>
217+
{
218+
{ CallIsolatedValue + "-new_projects", new { } }
219+
}
220+
};
221+
222+
protected override Func<RolloverIndexDescriptor, IRolloverIndexRequest> Fluent => f => f
223+
.NewIndex(CallIsolatedValue + "-new")
224+
.Conditions(c => c
225+
.MaxAge("7d")
226+
.MaxDocs(1000)
227+
.MaxSize("5gb")
228+
.MaxPrimaryShardSize("2gb")
229+
)
230+
.Settings(s => s
231+
.NumberOfShards(1)
232+
.NumberOfReplicas(1)
233+
)
234+
.Map<Project>(p => p
235+
.Properties(pp => pp
236+
.Text(t => t
237+
.Name(n => n.Branches)
238+
.Fields(pf => pf
239+
.Keyword(k => k
240+
.Name("keyword")
241+
.IgnoreAbove(256)
242+
)
243+
)
244+
)
245+
)
246+
)
247+
.Aliases(a => a
248+
.Alias(CallIsolatedValue + "-new_projects")
249+
);
250+
251+
protected override RolloverIndexRequest Initializer => new RolloverIndexRequest(CallIsolatedValue + "-alias", CallIsolatedValue + "-new")
252+
{
253+
Conditions = new RolloverConditions
254+
{
255+
MaxAge = "7d",
256+
MaxDocs = 1000,
257+
MaxSize = "5gb",
258+
MaxPrimaryShardSize = "2gb"
259+
},
260+
Settings = new Nest.IndexSettings
261+
{
262+
NumberOfShards = 1,
263+
NumberOfReplicas = 1
264+
},
265+
Mappings = new TypeMapping
266+
{
267+
Properties = new Properties<Project>
268+
{
269+
{
270+
p => p.Branches, new TextProperty
271+
{
272+
Fields = new Properties
273+
{
274+
{
275+
"keyword", new KeywordProperty
276+
{
277+
IgnoreAbove = 256
278+
}
279+
}
280+
}
281+
}
282+
}
283+
}
284+
},
285+
Aliases = new Aliases
286+
{
287+
{ CallIsolatedValue + "-new_projects", new Alias() }
288+
}
289+
};
290+
291+
protected override void OnBeforeCall(IElasticClient client)
292+
{
293+
var create = client.Indices.Create(CallIsolatedValue, c => c
294+
.Aliases(a => a
295+
.Alias(CallIsolatedValue + "-alias")
296+
)
297+
);
298+
create.ShouldBeValid();
299+
var someDocs = client.Bulk(b => b
300+
.Index(CallIsolatedValue)
301+
.Refresh(Refresh.True)
302+
.IndexMany(Project.Generator.Generate(1200))
303+
);
304+
someDocs.ShouldBeValid();
305+
306+
}
307+
308+
protected override LazyResponses ClientUsage() => Calls(
309+
(client, f) => client.Indices.Rollover(CallIsolatedValue + "-alias", f),
310+
(client, f) => client.Indices.RolloverAsync(CallIsolatedValue + "-alias", f),
311+
(client, r) => client.Indices.Rollover(r),
312+
(client, r) => client.Indices.RolloverAsync(r)
313+
);
314+
315+
protected override RolloverIndexDescriptor NewDescriptor() => new RolloverIndexDescriptor(CallIsolatedValue + "-alias");
316+
317+
protected override void ExpectResponse(RolloverIndexResponse response)
318+
{
319+
response.ShouldBeValid();
320+
response.OldIndex.Should().NotBeNullOrEmpty();
321+
response.NewIndex.Should().NotBeNullOrEmpty();
322+
response.RolledOver.Should().BeTrue();
323+
response.ShardsAcknowledged.Should().BeTrue();
324+
response.Conditions.Should().NotBeNull().And.HaveCount(4);
325+
response.Conditions["[max_age: 7d]"].Should().BeFalse();
326+
response.Conditions["[max_docs: 1000]"].Should().BeTrue();
327+
response.Conditions["[max_size: 5gb]"].Should().BeFalse();
328+
response.Conditions["[max_primary_shard_size: 2gb]"].Should().BeFalse();
329+
}
330+
}
169331
}

0 commit comments

Comments
 (0)