File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed
src/Elastic.Ingest.Elasticsearch Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -51,4 +51,9 @@ public IndexChannelOptions(HttpTransport transport) : base(transport) { }
5151 /// <para>https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html#bulk-api-request-body</para>
5252 /// </summary>
5353 public Func < TEvent , string , bool > ? BulkUpsertLookup { get ; set ; }
54+
55+ /// <summary>
56+ /// Control the operation header for each bulk operation.
57+ /// </summary>
58+ public OperationMode OperationMode { get ; set ; }
5459}
Original file line number Diff line number Diff line change 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+ namespace Elastic . Ingest . Elasticsearch . Indices ;
5+
6+ /// <summary>
7+ /// Determines the operation header for each bulk operation.
8+ /// </summary>
9+ public enum OperationMode
10+ {
11+ /// <summary>
12+ /// The mode will be determined automatically based on default rules for the preferred mode.
13+ /// </summary>
14+ Auto = 0 ,
15+
16+ /// <summary>
17+ /// Each document will be sent with an 'index' bulk operation header.
18+ /// </summary>
19+ Index = 1 ,
20+
21+ /// <summary>
22+ /// Each document will be sent with a 'create' bulk operation header.
23+ /// </summary>
24+ Create = 2
25+ }
Original file line number Diff line number Diff line change @@ -138,6 +138,20 @@ public static BulkOperationHeader CreateBulkOperationHeaderForIndex<TEvent>(TEve
138138
139139 var id = options . BulkOperationIdLookup ? . Invoke ( @event ) ;
140140
141+ if ( options . OperationMode == OperationMode . Index )
142+ {
143+ return skipIndexName
144+ ? ! string . IsNullOrWhiteSpace ( id ) ? new IndexOperation { Id = id } : new IndexOperation ( )
145+ : ! string . IsNullOrWhiteSpace ( id ) ? new IndexOperation { Index = index , Id = id } : new IndexOperation { Index = index } ;
146+ }
147+
148+ if ( options . OperationMode == OperationMode . Create )
149+ {
150+ return skipIndexName
151+ ? ! string . IsNullOrWhiteSpace ( id ) ? new CreateOperation { Id = id } : new CreateOperation ( )
152+ : ! string . IsNullOrWhiteSpace ( id ) ? new CreateOperation { Index = index , Id = id } : new CreateOperation { Index = index } ;
153+ }
154+
141155 if ( ! string . IsNullOrWhiteSpace ( id ) && id != null && ( options . BulkUpsertLookup ? . Invoke ( @event , id ) ?? false ) )
142156 return skipIndexName ? new UpdateOperation { Id = id } : new UpdateOperation { Id = id , Index = index } ;
143157
You can’t perform that action at this time.
0 commit comments