@@ -12,13 +12,6 @@ namespace Nest.Tests.Integration.Core
12
12
[ TestFixture ]
13
13
public class DeleteTests : IntegrationTests
14
14
{
15
- protected override void ResetIndexes ( )
16
- {
17
- IntegrationSetup . TearDown ( ) ;
18
- IntegrationSetup . Setup ( ) ;
19
- }
20
-
21
-
22
15
[ Test ]
23
16
public void ShouldNotThrowOnIdOverload ( )
24
17
{
@@ -40,23 +33,24 @@ public void ShouldThowOnNullId()
40
33
[ Test ]
41
34
public void GetDocumentById ( )
42
35
{
43
- //arrange
44
- //pull existing example through method we know is functional based on other passing unit tests
45
- var queryResults = this . SearchRaw < ElasticsearchProject > (
46
- @" { ""query"" : {
47
- ""fuzzy"" : {
48
- ""followers.firstName"" : """ + NestTestData . Data . First ( ) . Followers . First ( ) . FirstName . ToLowerInvariant ( ) + @"x""
49
- }
50
- } }"
36
+
37
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
38
+ var firstName = NestTestData . Data . First ( ) . Followers . First ( ) . FirstName . ToLowerInvariant ( ) ;
39
+ var queryResults = this . Client . Search < ElasticsearchProject > ( s => s
40
+ . Index ( newIndex )
41
+ . Query ( q =>
42
+ q . Fuzzy ( fq => fq . OnField ( p => p . Followers . First ( ) . FirstName ) . Value ( firstName + "x" ) )
43
+ )
51
44
) ;
45
+
52
46
Assert . Greater ( queryResults . Total , 0 ) ;
53
47
54
48
var hit = queryResults . HitsMetaData . Hits . First ( ) ;
55
49
var documentToFind = hit . Source ;
56
50
57
51
//act
58
52
//attempt to grab the same document using the document's id
59
- var foundDocument = this . Client . Source < ElasticsearchProject > ( hit . Id ) ;
53
+ var foundDocument = this . Client . Source < ElasticsearchProject > ( hit . Id , newIndex ) ;
60
54
61
55
//assert
62
56
//make sure that these are in fact the same documents
@@ -69,44 +63,33 @@ public void GetDocumentById()
69
63
[ Test ]
70
64
public void IndexThanDeleteDocumentById ( )
71
65
{
72
- //arrange
73
- //create a new document to index
74
- ElasticsearchProject newDocument = new ElasticsearchProject
66
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
67
+ var newDocument = new ElasticsearchProject
75
68
{
76
69
Country = "Mozambique" ,
77
70
Followers = new List < Person > ( ) ,
78
- Id = DateTime . Now . Millisecond + 1500 , //try to get this example out of the way of existing test data
71
+ Id = DateTime . Now . Millisecond + 1500 ,
79
72
Name = "Test Document for 'IndexDocument' test"
80
73
} ;
81
74
82
- //act
83
- //index the new item
84
- this . Client . Index < ElasticsearchProject > ( newDocument , i=> i . Refresh ( ) ) ;
75
+ this . Client . Index < ElasticsearchProject > ( newDocument , i=> i . Index ( newIndex ) . Refresh ( ) ) ;
85
76
86
- //assert
87
- //grab document back from the index and make sure it is the same document
88
- var foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id ) ;
77
+ var foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id , newIndex ) ;
89
78
90
- //Assert.Equal(newDocument.Country, foundDocument.Country);
91
79
Assert . AreEqual ( newDocument . Followers . Count , foundDocument . Followers . Count ) ;
92
80
Assert . AreEqual ( newDocument . Id , foundDocument . Id ) ;
93
81
Assert . AreEqual ( newDocument . Name , foundDocument . Name ) ;
94
82
95
- //act
96
- //now remove the item that was added
97
- var response = this . Client . Delete < ElasticsearchProject > ( f=> f . Id ( newDocument . Id ) . Refresh ( ) ) ;
83
+ var response = this . Client . Delete < ElasticsearchProject > ( f=> f . Id ( newDocument . Id ) . Index ( newIndex ) . Refresh ( ) ) ;
98
84
99
- //assert
100
- //make sure getting by id returns nothing
101
- foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id ) ;
85
+ foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id , newIndex ) ;
102
86
Assert . Null ( foundDocument ) ;
103
87
}
104
88
[ Test ]
105
89
public void IndexThanDeleteDocumentByObject ( )
106
90
{
107
- //arrange
108
- //create a new document to index
109
- ElasticsearchProject newDocument = new ElasticsearchProject
91
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
92
+ var newDocument = new ElasticsearchProject
110
93
{
111
94
Country = "Mozambique" ,
112
95
Followers = new List < Person > ( ) ,
@@ -116,11 +99,11 @@ public void IndexThanDeleteDocumentByObject()
116
99
117
100
//act
118
101
//index the new item
119
- this . Client . Index ( newDocument , i=> i . Refresh ( ) ) ;
102
+ this . Client . Index ( newDocument , i=> i . Refresh ( ) . Index ( newIndex ) ) ;
120
103
121
104
//assert
122
105
//grab document back from the index and make sure it is the same document
123
- var foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id ) ;
106
+ var foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id , newIndex ) ;
124
107
125
108
//Assert.Equal(newDocument.Country, foundDocument.Country);
126
109
Assert . AreEqual ( newDocument . Followers . Count , foundDocument . Followers . Count ) ;
@@ -129,98 +112,110 @@ public void IndexThanDeleteDocumentByObject()
129
112
130
113
//act
131
114
//now remove the item that was added
132
- this . Client . Delete < ElasticsearchProject > ( f=> f . IdFrom ( newDocument ) . Refresh ( ) ) ;
115
+ this . Client . Delete < ElasticsearchProject > ( f=> f . IdFrom ( newDocument ) . Refresh ( ) . Index ( newIndex ) ) ;
133
116
134
117
//assert
135
118
//make sure getting by id returns nothing
136
- foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id ) ;
119
+ foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id , newIndex ) ;
137
120
Assert . Null ( foundDocument ) ;
138
121
}
139
122
140
123
[ Test ]
141
124
public void IndexThenDeleteUsingRefresh ( )
142
125
{
143
- //arrange
144
- //create a new document to index
145
- ElasticsearchProject newDocument = new ElasticsearchProject
126
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
127
+ var newDocument = new ElasticsearchProject
146
128
{
147
129
Country = "Mozambique" ,
148
130
Followers = new List < Person > ( ) ,
149
- Id = DateTime . Now . Millisecond + 1500 , //try to get this example out of the way of existing test data
131
+ Id = DateTime . Now . Millisecond + 1500 ,
150
132
Name = "Test Document for 'IndexDocument' test"
151
133
} ;
152
134
153
- //act
154
- //index the new item
155
- this . Client . Index ( newDocument , i=> i . Refresh ( ) ) ;
135
+ this . Client . Index ( newDocument , i=> i . Refresh ( ) . Index ( newIndex ) ) ;
156
136
157
- //assert
158
137
//grab document back from the index and make sure it is the same document
159
- var foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id ) ;
138
+ var foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id , newIndex ) ;
160
139
161
- //Assert.Equal(newDocument.Country, foundDocument.Country);
162
140
Assert . AreEqual ( newDocument . Followers . Count , foundDocument . Followers . Count ) ;
163
141
Assert . AreEqual ( newDocument . Id , foundDocument . Id ) ;
164
142
Assert . AreEqual ( newDocument . Name , foundDocument . Name ) ;
165
143
166
- //act
167
144
//now remove the item that was added
168
- this . Client . Delete < ElasticsearchProject > ( d=> d . IdFrom ( newDocument ) . Refresh ( ) ) ;
145
+ this . Client . Delete < ElasticsearchProject > ( d=> d . IdFrom ( newDocument ) . Refresh ( ) . Index ( newIndex ) ) ;
169
146
170
- //assert
171
147
//make sure getting by id returns nothing
172
- foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id ) ;
148
+ foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id , newIndex ) ;
173
149
Assert . Null ( foundDocument ) ;
174
150
}
175
151
[ Test ]
176
152
public void RemoveAllByPassingAsIEnumerable ( )
177
153
{
178
- this . ResetIndexes ( ) ;
179
- var result = this . Client . Search < ElasticsearchProject > ( q => q . From ( 0 ) . Take ( 5 ) . MatchAll ( ) ) ;
154
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
155
+ var result = this . Client . Search < ElasticsearchProject > ( q => q
156
+ . Index ( newIndex )
157
+ . From ( 0 )
158
+ . Take ( 5 )
159
+ . MatchAll ( )
160
+ ) ;
180
161
Assert . IsNotEmpty ( result . Documents ) ;
181
162
182
163
var totalSet = result . Documents . Count ( ) ;
183
164
var totalResults = result . Total ;
184
165
Assert . Greater ( totalSet , 0 ) ;
185
166
186
- var deleteResult = this . Client . Bulk ( b => b . DeleteMany ( result . Documents ) . Refresh ( ) ) ;
167
+ var deleteResult = this . Client . Bulk ( b => b
168
+ . FixedPath ( newIndex )
169
+ . DeleteMany ( result . Documents ) . Refresh ( )
170
+ ) ;
187
171
Assert . True ( deleteResult . IsValid , deleteResult . ConnectionStatus . ResponseRaw . Utf8String ( ) ) ;
188
172
Assert . False ( deleteResult . Errors , deleteResult . ConnectionStatus . ResponseRaw . Utf8String ( ) ) ;
189
173
190
174
Assert . IsNotEmpty ( deleteResult . Items ) ;
191
175
192
- result = this . Client . Search < ElasticsearchProject > ( q => q . MatchAll ( ) ) ;
176
+ result = this . Client . Search < ElasticsearchProject > ( q => q . Index ( newIndex ) . MatchAll ( ) ) ;
193
177
Assert . IsNotEmpty ( result . Documents ) ;
194
178
Assert . AreEqual ( result . Total , totalResults - totalSet ) ;
195
179
196
180
}
197
181
[ Test ]
198
182
public void RemoveAllByPassingAsIEnumerableOfBulkParameters ( )
199
183
{
200
- this . ResetIndexes ( ) ;
201
- var result = this . Client . Search < ElasticsearchProject > ( q => q . MatchAll ( ) ) ;
184
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
185
+ var result = this . Client . Search < ElasticsearchProject > ( s => s
186
+ . Index ( newIndex )
187
+ . MatchAll ( )
188
+ ) ;
202
189
Assert . IsNotNull ( result ) ;
203
190
Assert . IsNotNull ( result . Documents ) ;
204
191
var totalSet = result . Documents . Count ( ) ;
205
192
Assert . Greater ( totalSet , 0 ) ;
206
193
var totalResults = result . Total ;
207
194
208
- var deleteResult = this . Client . Bulk ( b=> b . DeleteMany ( result . Documents , ( p , o ) => p . VersionType ( VersionType . Internal ) ) . Refresh ( ) ) ;
195
+ var deleteResult = this . Client . Bulk ( b=> b
196
+ . FixedPath ( newIndex )
197
+ . DeleteMany ( result . Documents , ( p , o ) => p . VersionType ( VersionType . Internal ) )
198
+ . Refresh ( )
199
+ ) ;
209
200
Assert . True ( deleteResult . IsValid , deleteResult . ConnectionStatus . ResponseRaw . Utf8String ( ) ) ;
210
201
Assert . False ( deleteResult . Errors , deleteResult . ConnectionStatus . ResponseRaw . Utf8String ( ) ) ;
211
202
212
203
Assert . IsNotEmpty ( deleteResult . Items ) ;
213
204
214
- result = this . Client . Search < ElasticsearchProject > ( q => q . MatchAll ( ) ) ;
205
+ result = this . Client . Search < ElasticsearchProject > ( s => s
206
+ . Index ( newIndex )
207
+ . MatchAll ( )
208
+ ) ;
215
209
Assert . IsNotNull ( result ) ;
216
210
Assert . IsNotNull ( result . Documents ) ;
217
211
Assert . AreEqual ( result . Total , totalResults - totalSet ) ;
218
212
}
219
213
[ Test ]
220
214
public void RemoveAllByQuery ( )
221
215
{
222
- this . ResetIndexes ( ) ;
216
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
223
217
var result = this . Client . Search < ElasticsearchProject > ( s => s
218
+ . Index ( newIndex )
224
219
. Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
225
220
) ;
226
221
Assert . IsNotNull ( result ) ;
@@ -229,6 +224,7 @@ public void RemoveAllByQuery()
229
224
Assert . Greater ( totalSet , 0 ) ;
230
225
var totalResults = result . Total ;
231
226
var deleteResult = this . Client . DeleteByQuery < ElasticsearchProject > ( d => d
227
+ . Index ( newIndex )
232
228
. Query ( q=> q
233
229
. Term ( f => f . Name , "elasticsearch.pm" )
234
230
)
@@ -237,27 +233,29 @@ public void RemoveAllByQuery()
237
233
deleteResult . IsValid . Should ( ) . BeTrue ( ) ;
238
234
239
235
result = this . Client . Search < ElasticsearchProject > ( s => s
236
+ . Index ( newIndex )
240
237
. Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
241
238
) ;
242
239
Assert . IsNotNull ( result ) ;
243
240
Assert . IsNotNull ( result . Documents ) ;
244
241
Assert . True ( result . Total == 0 ) ;
245
242
246
243
//make sure we did not delete all.
247
- var countResult = this . Client . Count ( c=> c . Query ( q => q . MatchAll ( ) ) ) ;
244
+ var countResult = this . Client . Count ( c=> c
245
+ . Index ( newIndex )
246
+ . Query ( q => q . MatchAll ( ) )
247
+ ) ;
248
248
Assert . True ( countResult . IsValid ) ;
249
249
Assert . Greater ( countResult . Count , 0 ) ;
250
250
251
251
}
252
252
[ Test ]
253
253
public void RemoveAllByTermQuery ( )
254
254
{
255
- var deleteQuery = @" {
256
- ""term"" : { ""name"" : ""elasticsearch.pm"" }
257
- }" ;
258
- var query = @" { ""query"" : " + deleteQuery + "}" ;
259
- this . ResetIndexes ( ) ;
255
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
256
+
260
257
var result = this . Client . Search < ElasticsearchProject > ( s => s
258
+ . Index ( newIndex )
261
259
. Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
262
260
) ;
263
261
Assert . IsNotNull ( result ) ;
@@ -266,6 +264,7 @@ public void RemoveAllByTermQuery()
266
264
Assert . Greater ( totalSet , 0 ) ;
267
265
var totalResults = result . Total ;
268
266
var deleteResult = this . Client . DeleteByQuery < ElasticsearchProject > ( d => d
267
+ . Index ( newIndex )
269
268
. Query ( q=> q
270
269
. Term ( f => f . Name , "elasticsearch.pm" )
271
270
)
@@ -274,22 +273,27 @@ public void RemoveAllByTermQuery()
274
273
deleteResult . IsValid . Should ( ) . BeTrue ( ) ;
275
274
276
275
result = this . Client . Search < ElasticsearchProject > ( s => s
276
+ . Index ( newIndex )
277
277
. Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
278
278
) ;
279
279
Assert . IsNotNull ( result ) ;
280
280
Assert . IsNotNull ( result . Documents ) ;
281
281
Assert . True ( result . Total == 0 ) ;
282
282
283
283
//make sure we did not delete all.
284
- var countResult = this . Client . Count < ElasticsearchProject > ( c=> c . Query ( q => q . MatchAll ( ) ) ) ;
284
+ var countResult = this . Client . Count < ElasticsearchProject > ( c=> c
285
+ . Index ( newIndex )
286
+ . Query ( q => q . MatchAll ( ) )
287
+ ) ;
285
288
Assert . True ( countResult . IsValid ) ;
286
289
Assert . Greater ( countResult . Count , 0 ) ;
287
290
}
288
291
[ Test ]
289
292
public void RemoveAllByQueryOverIndices ( )
290
293
{
291
- this . ResetIndexes ( ) ;
294
+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
292
295
var result = this . Client . Search < ElasticsearchProject > ( s => s
296
+ . Index ( newIndex )
293
297
. Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
294
298
) ;
295
299
Assert . IsNotNull ( result ) ;
@@ -300,23 +304,26 @@ public void RemoveAllByQueryOverIndices()
300
304
this . Client . DeleteByQuery < ElasticsearchProject > ( d => d
301
305
. Indices ( new [ ]
302
306
{
303
- ElasticsearchConfiguration . DefaultIndex ,
304
- ElasticsearchConfiguration . DefaultIndex + "_clone"
307
+ newIndex
305
308
} )
306
309
. Query ( q=> q
307
310
. Term ( f => f . Name , "elasticsearch.pm" )
308
311
)
309
312
) ;
310
313
311
314
result = this . Client . Search < ElasticsearchProject > ( s => s
315
+ . Index ( newIndex )
312
316
. Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
313
317
) ;
314
318
Assert . IsNotNull ( result ) ;
315
319
Assert . IsNotNull ( result . Documents ) ;
316
320
Assert . True ( result . Total == 0 ) ;
317
321
318
322
//make sure we did not delete all.
319
- var countResult = this . Client . Count < ElasticsearchProject > ( c=> c . Query ( q => q . MatchAll ( ) ) ) ;
323
+ var countResult = this . Client . Count < ElasticsearchProject > ( c=> c
324
+ . Index ( newIndex )
325
+ . Query ( q => q . MatchAll ( ) )
326
+ ) ;
320
327
Assert . True ( countResult . IsValid ) ;
321
328
Assert . Greater ( countResult . Count , 0 ) ;
322
329
0 commit comments