|
4 | 4 |
|
5 | 5 | using System;
|
6 | 6 | using System.Collections.Generic;
|
7 |
| -using System.Text.Json; |
| 7 | + |
8 | 8 | using Elastic.Transport;
|
9 | 9 | using Elastic.Clients.Elasticsearch.Core.Bulk;
|
10 | 10 |
|
11 | 11 | namespace Elastic.Clients.Elasticsearch;
|
12 | 12 |
|
13 |
| -public sealed class BulkAllRequest<T> : IBulkAllRequest<T>, IHelperCallable |
| 13 | +public sealed class BulkAllRequest<T> : |
| 14 | + IHelperCallable |
14 | 15 | {
|
15 | 16 | public BulkAllRequest(IEnumerable<T> documents)
|
16 | 17 | {
|
@@ -58,97 +59,121 @@ public BulkAllRequest(IEnumerable<T> documents)
|
58 | 59 | RequestMetaData IHelperCallable.ParentMetaData { get => ParentMetaData; set => ParentMetaData = value; }
|
59 | 60 | }
|
60 | 61 |
|
61 |
| -// TODO: |
62 |
| - |
63 |
| -//public sealed class BulkAllRequestDescriptor<T> : SerializableDescriptor<BulkAllRequestDescriptor<T>>, IBulkAllRequest<T>, IHelperCallable |
64 |
| -//{ |
65 |
| -// private readonly IEnumerable<T> _documents; |
66 |
| - |
67 |
| -// private int? _backOffRetries; |
68 |
| -// private Duration _backOffTime; |
69 |
| -// private ProducerConsumerBackPressure _backPressure; |
70 |
| -// private Action<BulkResponse> _bulkResponseCallback; |
71 |
| -// private IndexName _index; |
72 |
| -// private int? _maxDegreeOfParallism; |
73 |
| -// private int? _size; |
74 |
| -// private bool _refreshOnCompleted; |
75 |
| -// private Action<BulkRequestDescriptor, IList<T>> _bufferToBulk; |
76 |
| -// private Func<ResponseItem, T, bool> _retryDocumentPredicate; |
77 |
| -// private Action<ResponseItem, T> _droppedDocumentCallback; |
78 |
| -// private Routing _routing; |
79 |
| -// private bool _continueAfterDroppedDocuments; |
80 |
| -// private string _pipeline; |
81 |
| -// private Indices _refreshIndices; |
82 |
| -// private Duration _timeout; |
83 |
| -// private WaitForActiveShards? _waitForActiveShards; |
84 |
| -// private RequestMetaData _requestMetaData; |
85 | 62 |
|
86 |
| -// public BulkAllRequestDescriptor(IEnumerable<T> documents) |
87 |
| -// { |
88 |
| -// _documents = documents; |
89 |
| -// _index = typeof(T); |
90 |
| -// } |
91 |
| - |
92 |
| -// int? IBulkAllRequest<T>.BackOffRetries => _backOffRetries; |
93 |
| -// Duration? IBulkAllRequest<T>.BackOffTime => _backOffTime; |
94 |
| -// ProducerConsumerBackPressure? IBulkAllRequest<T>.BackPressure => _backPressure; |
95 |
| -// Action<BulkRequestDescriptor, IList<T>>? IBulkAllRequest<T>.BufferToBulk => _bufferToBulk; |
96 |
| -// Action<BulkResponse>? IBulkAllRequest<T>.BulkResponseCallback => _bulkResponseCallback; |
97 |
| -// bool IBulkAllRequest<T>.ContinueAfterDroppedDocuments => _continueAfterDroppedDocuments; |
98 |
| -// IEnumerable<T> IBulkAllRequest<T>.Documents => _documents; |
99 |
| -// Action<ResponseItem, T>? IBulkAllRequest<T>.DroppedDocumentCallback => _droppedDocumentCallback; |
100 |
| -// IndexName IBulkAllRequest<T>.Index => _index; |
101 |
| -// int? IBulkAllRequest<T>.MaxDegreeOfParallelism => _maxDegreeOfParallism; |
102 |
| -// string? IBulkAllRequest<T>.Pipeline => _pipeline; |
103 |
| -// Indices? IBulkAllRequest<T>.RefreshIndices => _refreshIndices; |
104 |
| -// bool IBulkAllRequest<T>.RefreshOnCompleted => _refreshOnCompleted; |
105 |
| -// Func<ResponseItem, T, bool>? IBulkAllRequest<T>.RetryDocumentPredicate => _retryDocumentPredicate; |
106 |
| -// Routing? IBulkAllRequest<T>.Routing => _routing; |
107 |
| -// int? IBulkAllRequest<T>.Size => _size; |
108 |
| -// Duration? IBulkAllRequest<T>.Timeout => _timeout; |
109 |
| -// WaitForActiveShards? IBulkAllRequest<T>.WaitForActiveShards => _waitForActiveShards; |
110 |
| -// RequestMetaData IHelperCallable.ParentMetaData { get => _requestMetaData; set => _requestMetaData = value; } |
| 63 | +public sealed class BulkAllRequestDescriptor<T> |
| 64 | +{ |
| 65 | + private BulkAllRequest<T> Instance { get; } |
111 | 66 |
|
112 |
| -// public BulkAllRequestDescriptor<T> BackOffRetries(int? backOffRetries) => Assign(backOffRetries, (a, v) => a._backOffRetries = v); |
| 67 | + public BulkAllRequestDescriptor(IEnumerable<T> documents) |
| 68 | + { |
| 69 | + Instance = new(documents); |
| 70 | + } |
113 | 71 |
|
114 |
| -// public BulkAllRequestDescriptor<T> BackOffTime(Duration? backOffTime) => Assign(backOffTime, (a, v) => a._backOffTime = v); |
| 72 | + public BulkAllRequestDescriptor<T> BackOffRetries(int? backOffRetries) |
| 73 | + { |
| 74 | + Instance.BackOffRetries = backOffRetries; |
| 75 | + return this; |
| 76 | + } |
115 | 77 |
|
116 |
| -// public BulkAllRequestDescriptor<T> BackPressure(int maxConcurrency, int? backPressureFactor = null) => |
117 |
| -// Assign(new ProducerConsumerBackPressure(backPressureFactor, maxConcurrency), (a, v) => a._backPressure = v); |
| 78 | + public BulkAllRequestDescriptor<T> BackOffTime(Duration? backOffTime) |
| 79 | + { |
| 80 | + Instance.BackOffTime = backOffTime; |
| 81 | + return this; |
| 82 | + } |
118 | 83 |
|
119 |
| -// public BulkAllRequestDescriptor<T> BufferToBulk(Action<BulkRequestDescriptor, IList<T>> modifier) => Assign(modifier, (a, v) => a._bufferToBulk = v); |
| 84 | + public BulkAllRequestDescriptor<T> BackPressure(int maxConcurrency, int? backPressureFactor = null) |
| 85 | + { |
| 86 | + Instance.BackPressure = new ProducerConsumerBackPressure(backPressureFactor, maxConcurrency); |
| 87 | + return this; |
| 88 | + } |
120 | 89 |
|
121 |
| -// public BulkAllRequestDescriptor<T> BulkResponseCallback(Action<BulkResponse> callback) => |
122 |
| -// Assign(callback, (a, v) => a._bulkResponseCallback = v); |
| 90 | + public BulkAllRequestDescriptor<T> BufferToBulk(Action<BulkRequestDescriptor, IList<T>> modifier) |
| 91 | + { |
| 92 | + Instance.BufferToBulk = modifier; |
| 93 | + return this; |
| 94 | + } |
123 | 95 |
|
124 |
| -// public BulkAllRequestDescriptor<T> ContinueAfterDroppedDocuments(bool proceed = true) => Assign(proceed, (a, v) => a._continueAfterDroppedDocuments = v); |
| 96 | + public BulkAllRequestDescriptor<T> BulkResponseCallback(Action<BulkResponse> callback) |
| 97 | + { |
| 98 | + Instance.BulkResponseCallback = callback; |
| 99 | + return this; |
| 100 | + } |
125 | 101 |
|
126 |
| -// public BulkAllRequestDescriptor<T> DroppedDocumentCallback(Action<ResponseItem, T> callback) => |
127 |
| -// Assign(callback, (a, v) => a._droppedDocumentCallback = v); |
| 102 | + public BulkAllRequestDescriptor<T> ContinueAfterDroppedDocuments(bool proceed = true) |
| 103 | + { |
| 104 | + Instance.ContinueAfterDroppedDocuments = proceed; |
| 105 | + return this; |
| 106 | + } |
128 | 107 |
|
129 |
| -// public BulkAllRequestDescriptor<T> Index(IndexName index) => Assign(index, (a, v) => a._index = v); |
| 108 | + public BulkAllRequestDescriptor<T> DroppedDocumentCallback(Action<ResponseItem, T> callback) |
| 109 | + { |
| 110 | + Instance.DroppedDocumentCallback = callback; |
| 111 | + return this; |
| 112 | + } |
130 | 113 |
|
131 |
| -// public BulkAllRequestDescriptor<T> Index<TOther>() where TOther : class => Assign(typeof(TOther), (a, v) => a._index = v); |
| 114 | + public BulkAllRequestDescriptor<T> Index(IndexName index) |
| 115 | + { |
| 116 | + Instance.Index = index; |
| 117 | + return this; |
| 118 | + } |
132 | 119 |
|
133 |
| -// public BulkAllRequestDescriptor<T> MaxDegreeOfParallelism(int? parallelism) => Assign(parallelism, (a, v) => a._maxDegreeOfParallism = v); |
| 120 | + public BulkAllRequestDescriptor<T> Index<TOther>() where TOther : class |
| 121 | + { |
| 122 | + Instance.Index = typeof(TOther); |
| 123 | + return this; |
| 124 | + } |
134 | 125 |
|
135 |
| -// public BulkAllRequestDescriptor<T> Pipeline(string pipeline) => Assign(pipeline, (a, v) => a._pipeline = v); |
| 126 | + public BulkAllRequestDescriptor<T> MaxDegreeOfParallelism(int? parallelism) |
| 127 | + { |
| 128 | + Instance.MaxDegreeOfParallelism = parallelism; |
| 129 | + return this; |
| 130 | + } |
136 | 131 |
|
137 |
| -// public BulkAllRequestDescriptor<T> RefreshIndices(Indices indicesToRefresh) => Assign(indicesToRefresh, (a, v) => a._refreshIndices = v); |
| 132 | + public BulkAllRequestDescriptor<T> Pipeline(string pipeline) |
| 133 | + { |
| 134 | + Instance.Pipeline = pipeline; |
| 135 | + return this; |
| 136 | + } |
138 | 137 |
|
139 |
| -// public BulkAllRequestDescriptor<T> RefreshOnCompleted(bool refreshOnCompleted = true) => Assign(refreshOnCompleted, (a, v) => a._refreshOnCompleted = v); |
| 138 | + public BulkAllRequestDescriptor<T> RefreshIndices(Indices indicesToRefresh) |
| 139 | + { |
| 140 | + Instance.RefreshIndices = indicesToRefresh; |
| 141 | + return this; |
| 142 | + } |
140 | 143 |
|
141 |
| -// public BulkAllRequestDescriptor<T> RetryDocumentPredicate(Func<ResponseItem, T, bool> predicate) => |
142 |
| -// Assign(predicate, (a, v) => a._retryDocumentPredicate = v); |
| 144 | + public BulkAllRequestDescriptor<T> RefreshOnCompleted(bool refreshOnCompleted = true) |
| 145 | + { |
| 146 | + Instance.RefreshOnCompleted = refreshOnCompleted; |
| 147 | + return this; |
| 148 | + } |
143 | 149 |
|
144 |
| -// public BulkAllRequestDescriptor<T> Routing(Routing routing) => Assign(routing, (a, v) => a._routing = v); |
| 150 | + public BulkAllRequestDescriptor<T> RetryDocumentPredicate(Func<ResponseItem, T, bool> predicate) |
| 151 | + { |
| 152 | + Instance.RetryDocumentPredicate = predicate; |
| 153 | + return this; |
| 154 | + } |
145 | 155 |
|
146 |
| -// public BulkAllRequestDescriptor<T> Size(int? size) => Assign(size, (a, v) => a._size = v); |
| 156 | + public BulkAllRequestDescriptor<T> Routing(Routing routing) |
| 157 | + { |
| 158 | + Instance.Routing = routing; |
| 159 | + return this; |
| 160 | + } |
147 | 161 |
|
148 |
| -// public BulkAllRequestDescriptor<T> Timeout(Duration timeout) => Assign(timeout, (a, v) => a._timeout = v); |
| 162 | + public BulkAllRequestDescriptor<T> Size(int? size) |
| 163 | + { |
| 164 | + Instance.Size = size; |
| 165 | + return this; |
| 166 | + } |
149 | 167 |
|
150 |
| -// public BulkAllRequestDescriptor<T> WaitForActiveShards(WaitForActiveShards? shards) => Assign(shards, (a, v) => a._waitForActiveShards = v); |
| 168 | + public BulkAllRequestDescriptor<T> Timeout(Duration timeout) |
| 169 | + { |
| 170 | + Instance.Timeout = timeout; |
| 171 | + return this; |
| 172 | + } |
151 | 173 |
|
152 |
| -// // This descriptor is not serializable and gets converted to a BullAllObservable |
153 |
| -// protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings) => throw new NotImplementedException(); |
154 |
| -//} |
| 174 | + public BulkAllRequestDescriptor<T> WaitForActiveShards(WaitForActiveShards? shards) |
| 175 | + { |
| 176 | + Instance.WaitForActiveShards = shards; |
| 177 | + return this; |
| 178 | + } |
| 179 | +} |
0 commit comments