@@ -12,13 +12,6 @@ namespace Nest.Tests.Integration.Core
1212 [ TestFixture ]
1313 public class DeleteTests : IntegrationTests
1414 {
15- protected override void ResetIndexes ( )
16- {
17- IntegrationSetup . TearDown ( ) ;
18- IntegrationSetup . Setup ( ) ;
19- }
20-
21-
2215 [ Test ]
2316 public void ShouldNotThrowOnIdOverload ( )
2417 {
@@ -40,23 +33,24 @@ public void ShouldThowOnNullId()
4033 [ Test ]
4134 public void GetDocumentById ( )
4235 {
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+ )
5144 ) ;
45+
5246 Assert . Greater ( queryResults . Total , 0 ) ;
5347
5448 var hit = queryResults . HitsMetaData . Hits . First ( ) ;
5549 var documentToFind = hit . Source ;
5650
5751 //act
5852 //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 ) ;
6054
6155 //assert
6256 //make sure that these are in fact the same documents
@@ -69,44 +63,33 @@ public void GetDocumentById()
6963 [ Test ]
7064 public void IndexThanDeleteDocumentById ( )
7165 {
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
7568 {
7669 Country = "Mozambique" ,
7770 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 ,
7972 Name = "Test Document for 'IndexDocument' test"
8073 } ;
8174
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 ( ) ) ;
8576
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 ) ;
8978
90- //Assert.Equal(newDocument.Country, foundDocument.Country);
9179 Assert . AreEqual ( newDocument . Followers . Count , foundDocument . Followers . Count ) ;
9280 Assert . AreEqual ( newDocument . Id , foundDocument . Id ) ;
9381 Assert . AreEqual ( newDocument . Name , foundDocument . Name ) ;
9482
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 ( ) ) ;
9884
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 ) ;
10286 Assert . Null ( foundDocument ) ;
10387 }
10488 [ Test ]
10589 public void IndexThanDeleteDocumentByObject ( )
10690 {
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
11093 {
11194 Country = "Mozambique" ,
11295 Followers = new List < Person > ( ) ,
@@ -116,11 +99,11 @@ public void IndexThanDeleteDocumentByObject()
11699
117100 //act
118101 //index the new item
119- this . Client . Index ( newDocument , i=> i . Refresh ( ) ) ;
102+ this . Client . Index ( newDocument , i=> i . Refresh ( ) . Index ( newIndex ) ) ;
120103
121104 //assert
122105 //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 ) ;
124107
125108 //Assert.Equal(newDocument.Country, foundDocument.Country);
126109 Assert . AreEqual ( newDocument . Followers . Count , foundDocument . Followers . Count ) ;
@@ -129,98 +112,110 @@ public void IndexThanDeleteDocumentByObject()
129112
130113 //act
131114 //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 ) ) ;
133116
134117 //assert
135118 //make sure getting by id returns nothing
136- foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id ) ;
119+ foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id , newIndex ) ;
137120 Assert . Null ( foundDocument ) ;
138121 }
139122
140123 [ Test ]
141124 public void IndexThenDeleteUsingRefresh ( )
142125 {
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
146128 {
147129 Country = "Mozambique" ,
148130 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 ,
150132 Name = "Test Document for 'IndexDocument' test"
151133 } ;
152134
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 ) ) ;
156136
157- //assert
158137 //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 ) ;
160139
161- //Assert.Equal(newDocument.Country, foundDocument.Country);
162140 Assert . AreEqual ( newDocument . Followers . Count , foundDocument . Followers . Count ) ;
163141 Assert . AreEqual ( newDocument . Id , foundDocument . Id ) ;
164142 Assert . AreEqual ( newDocument . Name , foundDocument . Name ) ;
165143
166- //act
167144 //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 ) ) ;
169146
170- //assert
171147 //make sure getting by id returns nothing
172- foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id ) ;
148+ foundDocument = this . Client . Source < ElasticsearchProject > ( newDocument . Id , newIndex ) ;
173149 Assert . Null ( foundDocument ) ;
174150 }
175151 [ Test ]
176152 public void RemoveAllByPassingAsIEnumerable ( )
177153 {
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+ ) ;
180161 Assert . IsNotEmpty ( result . Documents ) ;
181162
182163 var totalSet = result . Documents . Count ( ) ;
183164 var totalResults = result . Total ;
184165 Assert . Greater ( totalSet , 0 ) ;
185166
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+ ) ;
187171 Assert . True ( deleteResult . IsValid , deleteResult . ConnectionStatus . ResponseRaw . Utf8String ( ) ) ;
188172 Assert . False ( deleteResult . Errors , deleteResult . ConnectionStatus . ResponseRaw . Utf8String ( ) ) ;
189173
190174 Assert . IsNotEmpty ( deleteResult . Items ) ;
191175
192- result = this . Client . Search < ElasticsearchProject > ( q => q . MatchAll ( ) ) ;
176+ result = this . Client . Search < ElasticsearchProject > ( q => q . Index ( newIndex ) . MatchAll ( ) ) ;
193177 Assert . IsNotEmpty ( result . Documents ) ;
194178 Assert . AreEqual ( result . Total , totalResults - totalSet ) ;
195179
196180 }
197181 [ Test ]
198182 public void RemoveAllByPassingAsIEnumerableOfBulkParameters ( )
199183 {
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+ ) ;
202189 Assert . IsNotNull ( result ) ;
203190 Assert . IsNotNull ( result . Documents ) ;
204191 var totalSet = result . Documents . Count ( ) ;
205192 Assert . Greater ( totalSet , 0 ) ;
206193 var totalResults = result . Total ;
207194
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+ ) ;
209200 Assert . True ( deleteResult . IsValid , deleteResult . ConnectionStatus . ResponseRaw . Utf8String ( ) ) ;
210201 Assert . False ( deleteResult . Errors , deleteResult . ConnectionStatus . ResponseRaw . Utf8String ( ) ) ;
211202
212203 Assert . IsNotEmpty ( deleteResult . Items ) ;
213204
214- result = this . Client . Search < ElasticsearchProject > ( q => q . MatchAll ( ) ) ;
205+ result = this . Client . Search < ElasticsearchProject > ( s => s
206+ . Index ( newIndex )
207+ . MatchAll ( )
208+ ) ;
215209 Assert . IsNotNull ( result ) ;
216210 Assert . IsNotNull ( result . Documents ) ;
217211 Assert . AreEqual ( result . Total , totalResults - totalSet ) ;
218212 }
219213 [ Test ]
220214 public void RemoveAllByQuery ( )
221215 {
222- this . ResetIndexes ( ) ;
216+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
223217 var result = this . Client . Search < ElasticsearchProject > ( s => s
218+ . Index ( newIndex )
224219 . Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
225220 ) ;
226221 Assert . IsNotNull ( result ) ;
@@ -229,6 +224,7 @@ public void RemoveAllByQuery()
229224 Assert . Greater ( totalSet , 0 ) ;
230225 var totalResults = result . Total ;
231226 var deleteResult = this . Client . DeleteByQuery < ElasticsearchProject > ( d => d
227+ . Index ( newIndex )
232228 . Query ( q=> q
233229 . Term ( f => f . Name , "elasticsearch.pm" )
234230 )
@@ -237,27 +233,29 @@ public void RemoveAllByQuery()
237233 deleteResult . IsValid . Should ( ) . BeTrue ( ) ;
238234
239235 result = this . Client . Search < ElasticsearchProject > ( s => s
236+ . Index ( newIndex )
240237 . Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
241238 ) ;
242239 Assert . IsNotNull ( result ) ;
243240 Assert . IsNotNull ( result . Documents ) ;
244241 Assert . True ( result . Total == 0 ) ;
245242
246243 //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+ ) ;
248248 Assert . True ( countResult . IsValid ) ;
249249 Assert . Greater ( countResult . Count , 0 ) ;
250250
251251 }
252252 [ Test ]
253253 public void RemoveAllByTermQuery ( )
254254 {
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+
260257 var result = this . Client . Search < ElasticsearchProject > ( s => s
258+ . Index ( newIndex )
261259 . Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
262260 ) ;
263261 Assert . IsNotNull ( result ) ;
@@ -266,6 +264,7 @@ public void RemoveAllByTermQuery()
266264 Assert . Greater ( totalSet , 0 ) ;
267265 var totalResults = result . Total ;
268266 var deleteResult = this . Client . DeleteByQuery < ElasticsearchProject > ( d => d
267+ . Index ( newIndex )
269268 . Query ( q=> q
270269 . Term ( f => f . Name , "elasticsearch.pm" )
271270 )
@@ -274,22 +273,27 @@ public void RemoveAllByTermQuery()
274273 deleteResult . IsValid . Should ( ) . BeTrue ( ) ;
275274
276275 result = this . Client . Search < ElasticsearchProject > ( s => s
276+ . Index ( newIndex )
277277 . Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
278278 ) ;
279279 Assert . IsNotNull ( result ) ;
280280 Assert . IsNotNull ( result . Documents ) ;
281281 Assert . True ( result . Total == 0 ) ;
282282
283283 //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+ ) ;
285288 Assert . True ( countResult . IsValid ) ;
286289 Assert . Greater ( countResult . Count , 0 ) ;
287290 }
288291 [ Test ]
289292 public void RemoveAllByQueryOverIndices ( )
290293 {
291- this . ResetIndexes ( ) ;
294+ var newIndex = IntegrationSetup . CreateNewIndexWithData ( this . Client ) ;
292295 var result = this . Client . Search < ElasticsearchProject > ( s => s
296+ . Index ( newIndex )
293297 . Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
294298 ) ;
295299 Assert . IsNotNull ( result ) ;
@@ -300,23 +304,26 @@ public void RemoveAllByQueryOverIndices()
300304 this . Client . DeleteByQuery < ElasticsearchProject > ( d => d
301305 . Indices ( new [ ]
302306 {
303- ElasticsearchConfiguration . DefaultIndex ,
304- ElasticsearchConfiguration . DefaultIndex + "_clone"
307+ newIndex
305308 } )
306309 . Query ( q=> q
307310 . Term ( f => f . Name , "elasticsearch.pm" )
308311 )
309312 ) ;
310313
311314 result = this . Client . Search < ElasticsearchProject > ( s => s
315+ . Index ( newIndex )
312316 . Query ( q => q . Term ( f => f . Name , "elasticsearch.pm" ) )
313317 ) ;
314318 Assert . IsNotNull ( result ) ;
315319 Assert . IsNotNull ( result . Documents ) ;
316320 Assert . True ( result . Total == 0 ) ;
317321
318322 //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+ ) ;
320327 Assert . True ( countResult . IsValid ) ;
321328 Assert . Greater ( countResult . Count , 0 ) ;
322329
0 commit comments