19
19
package org .elasticsearch .search ;
20
20
21
21
import com .carrotsearch .hppc .IntArrayList ;
22
-
23
22
import org .apache .lucene .search .Query ;
24
23
import org .apache .lucene .store .AlreadyClosedException ;
25
24
import org .elasticsearch .action .ActionListener ;
59
58
import org .elasticsearch .script .MockScriptPlugin ;
60
59
import org .elasticsearch .script .Script ;
61
60
import org .elasticsearch .script .ScriptType ;
61
+ import org .elasticsearch .search .aggregations .InternalAggregation ;
62
+ import org .elasticsearch .search .aggregations .MultiBucketConsumerService ;
62
63
import org .elasticsearch .search .aggregations .bucket .global .GlobalAggregationBuilder ;
63
64
import org .elasticsearch .search .aggregations .bucket .terms .TermsAggregationBuilder ;
64
65
import org .elasticsearch .search .aggregations .support .ValueType ;
@@ -152,10 +153,11 @@ public void onQueryPhase(SearchContext context, long tookInNanos) {
152
153
153
154
@ Override
154
155
protected Settings nodeSettings () {
155
- return Settings .builder ().put ("search.default_search_timeout" , "5s" ).build ();
156
+ return Settings .builder ().put ("search.default_search_timeout" , "5s" )
157
+ .put (MultiBucketConsumerService .MAX_BUCKET_SETTING .getKey (), MultiBucketConsumerService .SOFT_LIMIT_MAX_BUCKETS ).build ();
156
158
}
157
159
158
- public void testClearOnClose () throws ExecutionException , InterruptedException {
160
+ public void testClearOnClose () {
159
161
createIndex ("index" );
160
162
client ().prepareIndex ("index" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
161
163
SearchResponse searchResponse = client ().prepareSearch ("index" ).setSize (1 ).setScroll ("1m" ).get ();
@@ -167,7 +169,7 @@ public void testClearOnClose() throws ExecutionException, InterruptedException {
167
169
assertEquals (0 , service .getActiveContexts ());
168
170
}
169
171
170
- public void testClearOnStop () throws ExecutionException , InterruptedException {
172
+ public void testClearOnStop () {
171
173
createIndex ("index" );
172
174
client ().prepareIndex ("index" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
173
175
SearchResponse searchResponse = client ().prepareSearch ("index" ).setSize (1 ).setScroll ("1m" ).get ();
@@ -179,7 +181,7 @@ public void testClearOnStop() throws ExecutionException, InterruptedException {
179
181
assertEquals (0 , service .getActiveContexts ());
180
182
}
181
183
182
- public void testClearIndexDelete () throws ExecutionException , InterruptedException {
184
+ public void testClearIndexDelete () {
183
185
createIndex ("index" );
184
186
client ().prepareIndex ("index" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
185
187
SearchResponse searchResponse = client ().prepareSearch ("index" ).setSize (1 ).setScroll ("1m" ).get ();
@@ -208,7 +210,7 @@ public void testCloseSearchContextOnRewriteException() {
208
210
assertEquals (activeRefs , indexShard .store ().refCount ());
209
211
}
210
212
211
- public void testSearchWhileIndexDeleted () throws IOException , InterruptedException {
213
+ public void testSearchWhileIndexDeleted () throws InterruptedException {
212
214
createIndex ("index" );
213
215
client ().prepareIndex ("index" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
214
216
@@ -443,15 +445,15 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) {
443
445
}
444
446
445
447
@ Override
446
- protected void doWriteTo (StreamOutput out ) throws IOException {
448
+ protected void doWriteTo (StreamOutput out ) {
447
449
}
448
450
449
451
@ Override
450
- protected void doXContent (XContentBuilder builder , Params params ) throws IOException {
452
+ protected void doXContent (XContentBuilder builder , Params params ) {
451
453
}
452
454
453
455
@ Override
454
- protected Query doToQuery (QueryShardContext context ) throws IOException {
456
+ protected Query doToQuery (QueryShardContext context ) {
455
457
return null ;
456
458
}
457
459
@@ -501,7 +503,6 @@ public void testCanMatch() throws IOException {
501
503
assertFalse (service .canMatch (new ShardSearchLocalRequest (indexShard .shardId (), 1 , SearchType .QUERY_THEN_FETCH ,
502
504
new SearchSourceBuilder ().query (new MatchNoneQueryBuilder ()), Strings .EMPTY_ARRAY , false ,
503
505
new AliasFilter (null , Strings .EMPTY_ARRAY ), 1f , allowPartialSearchResults , null , null )));
504
-
505
506
}
506
507
507
508
public void testCanRewriteToMatchNone () {
@@ -519,7 +520,6 @@ public void testCanRewriteToMatchNone() {
519
520
.suggest (new SuggestBuilder ())));
520
521
assertFalse (SearchService .canRewriteToMatchNone (new SearchSourceBuilder ().query (new TermQueryBuilder ("foo" , "bar" ))
521
522
.suggest (new SuggestBuilder ())));
522
-
523
523
}
524
524
525
525
public void testSetSearchThrottled () {
@@ -568,4 +568,17 @@ public void testExpandSearchThrottled() {
568
568
assertHitCount (client ().prepareSearch ().get (), 0L );
569
569
assertHitCount (client ().prepareSearch ().setIndicesOptions (IndicesOptions .STRICT_EXPAND_OPEN_FORBID_CLOSED ).get (), 1L );
570
570
}
571
+
572
+ public void testCreateReduceContext () {
573
+ final SearchService service = getInstanceFromNode (SearchService .class );
574
+ {
575
+ InternalAggregation .ReduceContext reduceContext = service .createReduceContext (true );
576
+ expectThrows (MultiBucketConsumerService .TooManyBucketsException .class ,
577
+ () -> reduceContext .consumeBucketsAndMaybeBreak (MultiBucketConsumerService .SOFT_LIMIT_MAX_BUCKETS + 1 ));
578
+ }
579
+ {
580
+ InternalAggregation .ReduceContext reduceContext = service .createReduceContext (false );
581
+ reduceContext .consumeBucketsAndMaybeBreak (MultiBucketConsumerService .SOFT_LIMIT_MAX_BUCKETS + 1 );
582
+ }
583
+ }
571
584
}
0 commit comments