Skip to content

Commit f319359

Browse files
authored
Support PIT, Fields and RuntimeFields on AsyncSearch (#5989)
1 parent b0a8753 commit f319359

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

src/Nest/Search/Search/SearchRequest.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ public partial interface ISearchRequest : ITypedSearchRequest
3939
bool? Explain { get; set; }
4040

4141
/// <summary>
42-
/// BETA: Allows for retrieving a list of document fields in the search response.
43-
/// <para>This functionality is in beta and is subject to change. </para>
42+
/// Allows for retrieving a list of document fields in the search response.
4443
/// </summary>
4544
[DataMember(Name = "fields")]
4645
Fields Fields { get; set; }

src/Nest/XPack/AsyncSearch/Submit/AsyncSearchSubmitRequest.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public partial interface IAsyncSearchSubmitRequest : ITypedSearchRequest
2626
[DataMember(Name = "explain")]
2727
bool? Explain { get; set; }
2828

29+
/// <inheritdoc cref="ISearchRequest.Fields"/>
30+
[DataMember(Name = "fields")]
31+
Fields Fields { get; set; }
32+
2933
/// <inheritdoc cref="ISearchRequest.From"/>
3034
[DataMember(Name = "from")]
3135
int? From { get; set; }
@@ -98,6 +102,14 @@ public partial interface IAsyncSearchSubmitRequest : ITypedSearchRequest
98102
/// <inheritdoc cref="ISearchRequest.Version"/>
99103
[DataMember(Name = "version")]
100104
bool? Version { get; set; }
105+
106+
/// <inheritdoc cref="ISearchRequest.PointInTime"/>
107+
[DataMember(Name = "pit")]
108+
IPointInTime PointInTime { get; set; }
109+
110+
/// <inheritdoc cref="ISearchRequest.RuntimeFields"/>
111+
[DataMember(Name = "runtime_mappings")]
112+
IRuntimeFields RuntimeFields { get; set; }
101113
}
102114

103115
[ReadAs(typeof(AsyncSearchSubmitRequest<>))]
@@ -118,6 +130,8 @@ public partial class AsyncSearchSubmitRequest
118130
/// <inheritdoc />
119131
public bool? Explain { get; set; }
120132
/// <inheritdoc />
133+
public Fields Fields { get; set; }
134+
/// <inheritdoc />
121135
public int? From { get; set; }
122136
/// <inheritdoc />
123137
public IHighlight Highlight { get; set; }
@@ -158,6 +172,10 @@ public partial class AsyncSearchSubmitRequest
158172
public bool? TrackTotalHits { get; set; }
159173
/// <inheritdoc />
160174
public bool? Version { get; set; }
175+
/// <inheritdoc />
176+
public IPointInTime PointInTime { get; set; }
177+
/// <inheritdoc />
178+
public IRuntimeFields RuntimeFields { get; set; }
161179

162180
Type ITypedSearchRequest.ClrType => null;
163181

@@ -179,6 +197,7 @@ public partial class AsyncSearchSubmitDescriptor<TInferDocument> where TInferDoc
179197
IFieldCollapse IAsyncSearchSubmitRequest.Collapse { get; set; }
180198
Fields IAsyncSearchSubmitRequest.DocValueFields { get; set; }
181199
bool? IAsyncSearchSubmitRequest.Explain { get; set; }
200+
Fields IAsyncSearchSubmitRequest.Fields { get; set; }
182201
int? IAsyncSearchSubmitRequest.From { get; set; }
183202
IHighlight IAsyncSearchSubmitRequest.Highlight { get; set; }
184203
IDictionary<IndexName, double> IAsyncSearchSubmitRequest.IndicesBoost { get; set; }
@@ -199,6 +218,8 @@ public partial class AsyncSearchSubmitDescriptor<TInferDocument> where TInferDoc
199218
bool? IAsyncSearchSubmitRequest.TrackScores { get; set; }
200219
bool? IAsyncSearchSubmitRequest.TrackTotalHits { get; set; }
201220
bool? IAsyncSearchSubmitRequest.Version { get; set; }
221+
IPointInTime IAsyncSearchSubmitRequest.PointInTime { get; set; }
222+
IRuntimeFields IAsyncSearchSubmitRequest.RuntimeFields { get; set; }
202223

203224
protected sealed override void RequestDefaults(AsyncSearchSubmitRequestParameters parameters) => TypedKeys();
204225

@@ -225,6 +246,17 @@ public AsyncSearchSubmitDescriptor<TInferDocument> Source(Func<SourceFilterDescr
225246
/// <inheritdoc cref="IAsyncSearchSubmitRequest.Size" />
226247
public AsyncSearchSubmitDescriptor<TInferDocument> Take(int? take) => Size(take);
227248

249+
/// <inheritdoc cref="IAsyncSearchSubmitRequest.Fields" />
250+
public AsyncSearchSubmitDescriptor<TInferDocument> Fields(Func<FieldsDescriptor<TInferDocument>, IPromise<Fields>> fields) =>
251+
Assign(fields, (a, v) => a.Fields = v?.Invoke(new FieldsDescriptor<TInferDocument>())?.Value);
252+
253+
/// <inheritdoc cref="IAsyncSearchSubmitRequest.Fields" />
254+
public AsyncSearchSubmitDescriptor<TInferDocument> Fields<TSource>(Func<FieldsDescriptor<TSource>, IPromise<Fields>> fields) where TSource : class =>
255+
Assign(fields, (a, v) => a.Fields = v?.Invoke(new FieldsDescriptor<TSource>())?.Value);
256+
257+
/// <inheritdoc cref="IAsyncSearchSubmitRequest.Fields" />
258+
public AsyncSearchSubmitDescriptor<TInferDocument> Fields(Fields fields) => Assign(fields, (a, v) => a.DocValueFields = v);
259+
228260
/// <inheritdoc cref="IAsyncSearchSubmitRequest.From" />
229261
public AsyncSearchSubmitDescriptor<TInferDocument> From(int? from) => Assign(from, (a, v) => a.From = v);
230262

@@ -324,5 +356,34 @@ public AsyncSearchSubmitDescriptor<TInferDocument> Rescore(Func<RescoringDescrip
324356

325357
/// <inheritdoc cref="IAsyncSearchSubmitRequest.TrackTotalHits" />
326358
public AsyncSearchSubmitDescriptor<TInferDocument> TrackTotalHits(bool? trackTotalHits = true) => Assign(trackTotalHits, (a, v) => a.TrackTotalHits = v);
359+
360+
/// <inheritdoc cref="IAsyncSearchSubmitRequest.PointInTime" />
361+
public AsyncSearchSubmitDescriptor<TInferDocument> PointInTime(string pitId)
362+
{
363+
Self.PointInTime = new PointInTime(pitId);
364+
return this;
365+
}
366+
367+
/// <inheritdoc cref="IAsyncSearchSubmitRequest.PointInTime" />
368+
public AsyncSearchSubmitDescriptor<TInferDocument> PointInTime(string pitId, Func<PointInTimeDescriptor, IPointInTime> pit) =>
369+
Assign(pit, (a, v) => a.PointInTime = v?.Invoke(new PointInTimeDescriptor(pitId)));
370+
371+
/// <inheritdoc cref="IAsyncSearchSubmitRequest.RuntimeFields" />
372+
public AsyncSearchSubmitDescriptor<TInferDocument> RuntimeFields(Func<RuntimeFieldsDescriptor<TInferDocument>, IPromise<IRuntimeFields>> runtimeFieldsSelector) =>
373+
Assign(runtimeFieldsSelector, (a, v) => a.RuntimeFields = v?.Invoke(new RuntimeFieldsDescriptor<TInferDocument>())?.Value);
374+
375+
/// <inheritdoc cref="IAsyncSearchSubmitRequest.RuntimeFields" />
376+
public AsyncSearchSubmitDescriptor<TInferDocument> RuntimeFields<TSource>(Func<RuntimeFieldsDescriptor<TSource>, IPromise<IRuntimeFields>> runtimeFieldsSelector) where TSource : class =>
377+
Assign(runtimeFieldsSelector, (a, v) => a.RuntimeFields = v?.Invoke(new RuntimeFieldsDescriptor<TSource>())?.Value);
378+
379+
protected override string ResolveUrl(RouteValues routeValues, IConnectionSettingsValues settings)
380+
{
381+
if (Self.PointInTime is object && !string.IsNullOrEmpty(Self.PointInTime.Id) && routeValues.ContainsKey("index"))
382+
{
383+
routeValues.Remove("index");
384+
}
385+
386+
return base.ResolveUrl(routeValues, settings);
387+
}
327388
}
328389
}

0 commit comments

Comments
 (0)