Skip to content

Commit cd3fa85

Browse files
authored
Add searchable snapshot action for ILM (#6275)
1 parent d613be3 commit cd3fa85

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.Runtime.Serialization;
6+
7+
namespace Nest
8+
{
9+
/// <summary>
10+
/// This action takes a snapshot of the managed index in the configured repository and mounts it as a
11+
/// searchable snapshot. If the index is part of a data stream, the mounted index replaces the original
12+
/// index in the stream.
13+
/// </summary>
14+
public interface ISearchableSnapshotAction : ILifecycleAction
15+
{
16+
/// <summary>
17+
/// The repository used to store the snapshot.
18+
/// </summary>
19+
[DataMember(Name = "snapshot_repository")]
20+
string SnapshotRepository { get; set; }
21+
22+
/// <summary>
23+
/// Force merges the managed index to one segment.
24+
/// </summary>
25+
[DataMember(Name = "force_merge_index")]
26+
bool? ForceMergeIndex { get; set; }
27+
}
28+
29+
public class SearchableSnapshotAction : ISearchableSnapshotAction
30+
{
31+
/// <inheritdoc />
32+
public string SnapshotRepository { get; set; }
33+
34+
/// <inheritdoc />
35+
public bool? ForceMergeIndex { get; set; }
36+
}
37+
38+
public class SearchableSnapshotActionDescriptor : DescriptorBase<SearchableSnapshotActionDescriptor, ISearchableSnapshotAction>, ISearchableSnapshotAction
39+
{
40+
/// <inheritdoc cref="ISearchableSnapshotAction.SnapshotRepository" />
41+
string ISearchableSnapshotAction.SnapshotRepository { get; set; }
42+
43+
/// <inheritdoc cref="ISearchableSnapshotAction.ForceMergeIndex" />
44+
bool? ISearchableSnapshotAction.ForceMergeIndex { get; set; }
45+
46+
/// <inheritdoc cref="ISearchableSnapshotAction.SnapshotRepository" />
47+
public SearchableSnapshotActionDescriptor SnapshotRepository(string snapshotRespository) =>
48+
Assign(snapshotRespository, (a, v) => a.SnapshotRepository = snapshotRespository);
49+
50+
/// <inheritdoc cref="ISearchableSnapshotAction.ForceMergeIndex" />
51+
public SearchableSnapshotActionDescriptor ForceMergeIndex(bool? forceMergeIndex = true) =>
52+
Assign(forceMergeIndex, (a, v) => a.ForceMergeIndex = forceMergeIndex);
53+
}
54+
}

src/Nest/XPack/Ilm/LifecycleActions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public LifecycleActions(IDictionary<string, ILifecycleAction> container) : base(
3737
/// <inheritdoc cref="IRolloverLifecycleAction"/>
3838
public void Add(IRolloverLifecycleAction action) => BackingDictionary.Add("rollover", action);
3939

40+
/// <inheritdoc cref="ISearchableSnapshotAction"/>
41+
public void Add(ISearchableSnapshotAction action) => BackingDictionary.Add("searchable_snapshot", action);
42+
4043
/// <inheritdoc cref="ISetPriorityLifecycleAction"/>
4144
public void Add(ISetPriorityLifecycleAction action) => BackingDictionary.Add("set_priority", action);
4245

@@ -64,6 +67,7 @@ internal class LifecycleActionsJsonFormatter : IJsonFormatter<ILifecycleActions>
6467
{ "shrink", 7 },
6568
{ "unfollow", 8 },
6669
{ "wait_for_snapshot", 9 },
70+
{ "searchable_snapshot", 10 },
6771
};
6872

6973
public ILifecycleActions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
@@ -125,6 +129,10 @@ public ILifecycleActions Deserialize(ref JsonReader reader, IJsonFormatterResolv
125129
lifecycleAction = formatterResolver.GetFormatter<WaitForSnapshotLifecycleAction>()
126130
.Deserialize(ref reader, formatterResolver);
127131
break;
132+
case 10:
133+
lifecycleAction = formatterResolver.GetFormatter<SearchableSnapshotAction>()
134+
.Deserialize(ref reader, formatterResolver);
135+
break;
128136
}
129137

130138
lifecycles.Add(type.Utf8String(), lifecycleAction);
@@ -173,6 +181,9 @@ public void Serialize(ref JsonWriter writer, ILifecycleActions value, IJsonForma
173181
case "rollover":
174182
Serialize<IRolloverLifecycleAction>(ref writer, action.Value, formatterResolver);
175183
break;
184+
case "searchable_snapshot":
185+
Serialize<ISearchableSnapshotAction>(ref writer, action.Value, formatterResolver);
186+
break;
176187
case "set_priority":
177188
Serialize<ISetPriorityLifecycleAction>(ref writer, action.Value, formatterResolver);
178189
break;
@@ -229,6 +240,10 @@ public LifecycleActionsDescriptor ReadOnly(Func<ReadOnlyLifecycleActionDescripto
229240
public LifecycleActionsDescriptor Rollover(Func<RolloverLifecycleActionDescriptor, IRolloverLifecycleAction> selector) =>
230241
Assign("rollover", selector.InvokeOrDefault(new RolloverLifecycleActionDescriptor()));
231242

243+
/// <inheritdoc cref="ISearchableSnapshotAction"/>
244+
public LifecycleActionsDescriptor SearchableSnapshot(Func<SearchableSnapshotAction, ISearchableSnapshotAction> selector) =>
245+
Assign("searchable_snapshot", selector.InvokeOrDefault(new SearchableSnapshotAction()));
246+
232247
/// <inheritdoc cref="ISetPriorityLifecycleAction"/>
233248
public LifecycleActionsDescriptor SetPriority(Func<SetPriorityLifecycleActionDescriptor, ISetPriorityLifecycleAction> selector) =>
234249
Assign("set_priority", selector.InvokeOrDefault(new SetPriorityLifecycleActionDescriptor()));

0 commit comments

Comments
 (0)