@@ -103,5 +103,76 @@ public void MultiPercolate_ReturnsExpectedResults()
103103 errorResponse . ServerError . Error . Should ( ) . NotBeNullOrWhiteSpace ( ) ;
104104
105105 }
106+
107+
108+ [ Test ]
109+ public void MultiPercolate_PrecolateMany_ReturnsExpectedResults ( )
110+ {
111+
112+ //lets start fresh using a new index
113+ var indexName = ElasticsearchConfiguration . NewUniqueIndexName ( ) ;
114+ IntegrationSetup . CreateTestIndex ( this . Client , indexName ) ;
115+
116+ // lets register several percolators in our new index that do a term match
117+ // on document name == indexname
118+ // we associate some metadata with the percolator so that we can later filter
119+ // the ones we want to execute easier
120+ foreach ( var i in Enumerable . Range ( 0 , 10 ) )
121+ {
122+ var registerPercolator = this . Client . RegisterPercolator ( new RegisterPercolatorRequest ( indexName , "my-percolator-" + i )
123+ {
124+ Query = new TermQuery
125+ {
126+ Field = Property . Path < ElasticsearchProject > ( p => p . Name . Suffix ( "sort" ) ) ,
127+ Value = indexName
128+ } ,
129+ MetaData = new Dictionary < string , object >
130+ {
131+ { "order" , i }
132+ }
133+ } ) ;
134+ registerPercolator . IsValid . Should ( ) . BeTrue ( ) ;
135+ }
136+
137+
138+ // Set up 2 projects to index both with indexName as Name
139+ var projects = Enumerable . Range ( 0 , 2 )
140+ . Select ( i => new ElasticsearchProject { Id = 1337 + i , Name = indexName } )
141+ . ToList ( ) ;
142+ this . Client . IndexMany ( projects , indexName ) ;
143+
144+ this . Client . Refresh ( r => r . Index ( indexName ) ) ;
145+
146+
147+ //Now we kick of multiple percolations
148+ var multiPercolateResponse = this . Client . MultiPercolate ( mp => mp
149+ //provding document in the percolate request
150+ . PercolateMany ( projects , ( perc , proj ) =>
151+ perc . Index ( indexName ) . Document ( proj )
152+ )
153+ ) ;
154+
155+ multiPercolateResponse . IsValid . Should ( ) . BeTrue ( ) ;
156+
157+ var percolateResponses = multiPercolateResponse . Responses . ToList ( ) ;
158+ percolateResponses . Should ( ) . NotBeEmpty ( ) . And . HaveCount ( 4 ) ;
159+
160+ var percolateResponse = percolateResponses [ 0 ] ;
161+ percolateResponse . Total . Should ( ) . Be ( 10 ) ;
162+ percolateResponse . Matches . Should ( ) . HaveCount ( 10 ) ;
163+
164+ var existingResponse = percolateResponses [ 1 ] ;
165+ existingResponse . Total . Should ( ) . Be ( 10 ) ;
166+ existingResponse . Matches . Should ( ) . HaveCount ( 10 ) ;
167+
168+ var countResponse = percolateResponses [ 2 ] ;
169+ countResponse . Total . Should ( ) . Be ( 2 ) ;
170+ countResponse . Matches . Should ( ) . BeNull ( ) ;
171+
172+ var errorResponse = percolateResponses [ 3 ] ;
173+ errorResponse . Total . Should ( ) . Be ( 0 ) ;
174+ errorResponse . ServerError . Error . Should ( ) . NotBeNullOrWhiteSpace ( ) ;
175+
176+ }
106177 }
107178}
0 commit comments