@@ -12,8 +12,8 @@ public class BulkTests : IntegrationTests
12
12
{
13
13
[ Test ]
14
14
public void Bulk ( )
15
- {
16
- //Detete so we know the create does not throw an error.
15
+ {
16
+ //Delete so we know the create does not throw an error.
17
17
this . _client . DeleteIndex ( ElasticsearchConfiguration . DefaultIndex ) ;
18
18
var result = this . _client . Bulk ( b => b
19
19
. Index < ElasticSearchProject > ( i => i . Object ( new ElasticSearchProject { Id = 2 } ) )
@@ -24,8 +24,8 @@ public void Bulk()
24
24
result . IsValid . Should ( ) . BeTrue ( ) ;
25
25
26
26
result . Items . Should ( ) . NotBeNull ( ) . And . NotBeEmpty ( ) . And . HaveCount ( 3 ) . And . OnlyContain ( r => r . OK ) ;
27
- var deleteResponses = result . Items . OfType < BulkDeleteResponseItem > ( ) ;
28
- var createResponses = result . Items . OfType < BulkCreateResponseItem > ( ) ;
27
+ var deleteResponses = result . Items . OfType < BulkDeleteResponseItem > ( ) ;
28
+ var createResponses = result . Items . OfType < BulkCreateResponseItem > ( ) ;
29
29
var indexResponses = result . Items . OfType < BulkIndexResponseItem > ( ) ;
30
30
31
31
deleteResponses . Should ( ) . HaveCount ( 1 ) ;
@@ -41,12 +41,12 @@ public void Bulk()
41
41
indexResponses . Should ( ) . HaveCount ( 1 ) ;
42
42
indexResponses . First ( ) . Id . Should ( ) . BeEquivalentTo ( "2" ) ;
43
43
indexResponses . First ( ) . Index . Should ( ) . BeEquivalentTo ( ElasticsearchConfiguration . DefaultIndex ) ;
44
- indexResponses . First ( ) . Type . Should ( ) . BeEquivalentTo ( this . GetTypeNameFor < ElasticSearchProject > ( ) ) ;
44
+ indexResponses . First ( ) . Type . Should ( ) . BeEquivalentTo ( this . GetTypeNameFor < ElasticSearchProject > ( ) ) ;
45
45
}
46
46
47
47
[ Test ]
48
48
public void BulkWithFixedIndex ( )
49
- {
49
+ {
50
50
var indexName = ElasticsearchConfiguration . NewUniqueIndexName ( ) ;
51
51
var result = this . _client . Bulk ( b => b
52
52
. FixedPath ( indexName , "mytype" )
@@ -116,7 +116,7 @@ public void BulkWithFixedIndexOveriddenIndividualy()
116
116
[ Test ]
117
117
public void BulkAlternativeWayOfWriting ( )
118
118
{
119
- this . _client . DeleteIndex ( ElasticsearchConfiguration . DefaultIndex ) ;
119
+ this . _client . DeleteIndex ( ElasticsearchConfiguration . DefaultIndex ) ;
120
120
121
121
var descriptor = new BulkDescriptor ( ) ;
122
122
foreach ( var i in Enumerable . Range ( 0 , 1000 ) )
@@ -128,7 +128,60 @@ public void BulkAlternativeWayOfWriting()
128
128
129
129
result . Items . Should ( ) . NotBeNull ( ) . And . NotBeEmpty ( ) . And . HaveCount ( 1000 ) . And . OnlyContain ( r => r . OK ) ;
130
130
131
- }
131
+ }
132
+
133
+ [ Test ]
134
+ public void BulkIndexWithPercolate ( )
135
+ {
136
+ // register up some percolator queries to test matching
137
+ var query1 = "bulkindex-test-doc-1" ;
138
+
139
+ this . _client . UnregisterPercolator < ElasticSearchProject > ( query1 ) ;
140
+
141
+ var perc = this . _client . RegisterPercolator < ElasticSearchProject > ( p => p
142
+ . Name ( query1 )
143
+ . Query ( q => q
144
+ . Term ( f => f . Country , "netherlands" )
145
+ )
146
+ ) ;
147
+
148
+ var descriptor = new BulkDescriptor ( ) ;
149
+
150
+ // match against any doc
151
+ descriptor . Index < ElasticSearchProject > ( i => i
152
+ . Object ( new ElasticSearchProject { Id = 2 , Country = "netherlands" } )
153
+ . Percolate ( "*" ) // match on any percolated docs
154
+ ) ;
155
+
156
+ // no percolate requested this time
157
+ descriptor . Index < ElasticSearchProject > ( i => i
158
+ . Object ( new ElasticSearchProject { Id = 3 , Country = "netherlands" } )
159
+ ) ;
160
+
161
+ var result = this . _client . Bulk ( descriptor ) ;
162
+
163
+ result . Should ( ) . NotBeNull ( ) ;
164
+ result . IsValid . Should ( ) . BeTrue ( ) ;
165
+
166
+ result . Items . Should ( ) . NotBeNull ( ) . And . NotBeEmpty ( ) . And . HaveCount ( 2 ) . And . OnlyContain ( r => r . OK ) ;
167
+ var indexResponses = result . Items . OfType < BulkIndexResponseItem > ( ) ;
168
+
169
+ // tests on percolated responses
170
+ indexResponses . Should ( ) . HaveCount ( 2 ) ;
171
+
172
+ indexResponses . First ( ) . Id . Should ( ) . BeEquivalentTo ( "2" ) ;
173
+ indexResponses . First ( ) . Index . Should ( ) . BeEquivalentTo ( ElasticsearchConfiguration . DefaultIndex ) ;
174
+ indexResponses . First ( ) . Type . Should ( ) . BeEquivalentTo ( this . GetTypeNameFor < ElasticSearchProject > ( ) ) ;
175
+ indexResponses . First ( ) . Matches . Should ( ) . NotBeNull ( ) ;
176
+
177
+ indexResponses . ElementAt ( 1 ) . Id . Should ( ) . BeEquivalentTo ( "3" ) ;
178
+ indexResponses . ElementAt ( 1 ) . Index . Should ( ) . BeEquivalentTo ( ElasticsearchConfiguration . DefaultIndex ) ;
179
+ indexResponses . ElementAt ( 1 ) . Type . Should ( ) . BeEquivalentTo ( this . GetTypeNameFor < ElasticSearchProject > ( ) ) ;
180
+ indexResponses . First ( ) . Matches . Should ( ) . BeNull ( ) ;
181
+
182
+ // cleanup
183
+ this . _client . UnregisterPercolator < ElasticSearchProject > ( query1 ) ;
184
+ }
132
185
133
186
}
134
187
}
0 commit comments