1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . CommandLine ;
4
4
using System . Diagnostics ;
8
8
using System . Threading . Tasks ;
9
9
using Elastic . Clients . Elasticsearch ;
10
10
using Elastic . Clients . Elasticsearch . Core . Search ;
11
- using Elastic . Clients . Elasticsearch . IndexManagement ;
12
11
using Microsoft . Data . Sqlite ;
13
12
using TreeHouse . Common ;
14
13
using TreeHouse . Common . CommandLine ;
@@ -63,7 +62,7 @@ static async Task IndexQuests(string elasticUrl, FileInfo source)
63
62
{
64
63
ElasticsearchClient client = CreateClient ( elasticUrl ) ;
65
64
66
- CreateIndexResponse response = await client . Indices . CreateAsync < Quest > ( i => i
65
+ await client . Indices . CreateAsync < Quest > ( i => i
67
66
. Settings ( s => s . SingleNode ( ) )
68
67
. Mappings ( m => m
69
68
. Properties ( p => p
@@ -76,14 +75,7 @@ static async Task IndexQuests(string elasticUrl, FileInfo source)
76
75
. TextEnglishWithKeyword ( x => x . Condition )
77
76
)
78
77
)
79
- ) ;
80
-
81
- if ( ! response . IsSuccess ( ) )
82
- {
83
- Console . WriteLine ( "Could not create index ol-quest." ) ;
84
- Console . WriteLine ( response ) ;
85
- return ;
86
- }
78
+ ) . CheckSuccess ( "creating index ol-quest" ) ;
87
79
88
80
using SqliteConnection connection = new ( new SqliteConnectionStringBuilder ( )
89
81
{
@@ -126,23 +118,17 @@ static async Task IndexQuests(string elasticUrl, FileInfo source)
126
118
quests . Add ( quest ) ;
127
119
}
128
120
129
- BulkResponse indexRespose = await client . IndexManyAsync ( quests ) ;
130
- if ( ! indexRespose . IsSuccess ( ) )
131
- {
132
- Console . WriteLine ( "Failed to index quests." ) ;
133
- Console . WriteLine ( indexRespose ) ;
134
- return ;
135
- }
121
+ await client . IndexManyAsync ( quests ) . CheckSuccess ( "indexing quests" ) ;
136
122
137
- await client . Indices . RefreshAsync < Quest > ( ) ;
138
- await client . Indices . ForcemergeAsync < Quest > ( ) ;
123
+ await client . Indices . RefreshAsync < Quest > ( ) . CheckSuccess ( ) ;
124
+ await client . Indices . ForcemergeAsync < Quest > ( ) . CheckSuccess ( ) ;
139
125
}
140
126
141
127
static async Task IndexDialogs ( string elasticUrl , FileInfo source )
142
128
{
143
129
ElasticsearchClient client = CreateClient ( elasticUrl ) ;
144
130
145
- CreateIndexResponse response = await client . Indices . CreateAsync < Dialog > ( i => i
131
+ await client . Indices . CreateAsync < Dialog > ( i => i
146
132
. Settings ( s => s . SingleNode ( ) )
147
133
. Mappings ( m => m
148
134
. Properties ( p => p
@@ -151,14 +137,7 @@ static async Task IndexDialogs(string elasticUrl, FileInfo source)
151
137
. IntegerNumber ( x => x . Ver )
152
138
)
153
139
)
154
- ) ;
155
-
156
- if ( ! response . IsSuccess ( ) )
157
- {
158
- Console . WriteLine ( "Could not create index ol-dialog." ) ;
159
- Console . WriteLine ( response ) ;
160
- return ;
161
- }
140
+ ) . CheckSuccess ( "creating index ol-dialog" ) ;
162
141
163
142
using SqliteConnection connection = new ( new SqliteConnectionStringBuilder ( )
164
143
{
@@ -183,23 +162,17 @@ static async Task IndexDialogs(string elasticUrl, FileInfo source)
183
162
} ) ;
184
163
}
185
164
186
- BulkResponse indexRespose = await client . IndexManyAsync ( dialogs ) ;
187
- if ( ! indexRespose . IsSuccess ( ) )
188
- {
189
- Console . WriteLine ( "Failed to index dialogs." ) ;
190
- Console . WriteLine ( indexRespose ) ;
191
- return ;
192
- }
165
+ await client . IndexManyAsync ( dialogs ) . CheckSuccess ( "indexing dialogs" ) ;
193
166
194
- await client . Indices . RefreshAsync < Dialog > ( ) ;
195
- await client . Indices . ForcemergeAsync < Dialog > ( ) ;
167
+ await client . Indices . RefreshAsync < Dialog > ( ) . CheckSuccess ( ) ;
168
+ await client . Indices . ForcemergeAsync < Dialog > ( ) . CheckSuccess ( ) ;
196
169
}
197
170
198
171
static async Task IndexImages ( string elasticUrl , DirectoryInfo source )
199
172
{
200
173
ElasticsearchClient client = CreateClient ( elasticUrl ) ;
201
174
202
- CreateIndexResponse response = await client . Indices . CreateAsync < Image > ( i => i
175
+ await client . Indices . CreateAsync < Image > ( i => i
203
176
. Settings ( s => s . SingleNode ( ) )
204
177
. Mappings ( m => m
205
178
. Properties ( p => p
@@ -211,14 +184,7 @@ static async Task IndexImages(string elasticUrl, DirectoryInfo source)
211
184
)
212
185
)
213
186
)
214
- ) ;
215
-
216
- if ( ! response . IsSuccess ( ) )
217
- {
218
- Console . WriteLine ( "Could not create index ol-image." ) ;
219
- Console . WriteLine ( response ) ;
220
- return ;
221
- }
187
+ ) . CheckSuccess ( "creating index ol-image" ) ;
222
188
223
189
int batchSize = 100 ;
224
190
@@ -245,23 +211,16 @@ static async Task IndexImages(string elasticUrl, DirectoryInfo source)
245
211
stopwatch . Stop ( ) ;
246
212
Console . WriteLine ( $ "{ batchIdx + 1 } /{ fileBatches . Count } { stopwatch . Elapsed } ") ;
247
213
248
- BulkResponse indexRespose = await client . IndexManyAsync (
214
+ await client . IndexManyAsync (
249
215
fileBatch . Zip ( featuresBatch ) . Select ( x => new Image {
250
216
FileName = x . First . FullName ,
251
217
Features = x . Second
252
218
} )
253
- ) ;
254
-
255
- if ( ! indexRespose . IsSuccess ( ) )
256
- {
257
- Console . WriteLine ( "Failed to index dialogs." ) ;
258
- Console . WriteLine ( indexRespose ) ;
259
- return ;
260
- }
219
+ ) . CheckSuccess ( "indexing images" ) ;
261
220
}
262
221
263
- await client . Indices . RefreshAsync < Image > ( ) ;
264
- await client . Indices . ForcemergeAsync < Image > ( ) ;
222
+ await client . Indices . RefreshAsync < Image > ( ) . CheckSuccess ( ) ;
223
+ await client . Indices . ForcemergeAsync < Image > ( ) . CheckSuccess ( ) ;
265
224
266
225
Console . WriteLine ( "done" ) ;
267
226
}
@@ -286,7 +245,7 @@ static async Task SearchImages(string elasticUrl, int size, FileInfo image)
286
245
. DocvalueFields ( f => f
287
246
. Field ( x => x . FileName )
288
247
)
289
- ) ;
248
+ ) . CheckSuccess ( ) ;
290
249
291
250
foreach ( Hit < Image > hit in response . Hits )
292
251
{
0 commit comments