@@ -228,105 +228,13 @@ void assertOldIndexWorks(String index) throws Exception {
228228 // node startup
229229 upgradeIndexFolder ();
230230 importIndex (indexName );
231- assertAllSearchWorks (indexName );
232- assertBasicAggregationWorks (indexName );
233- assertRealtimeGetWorks (indexName );
234- assertNewReplicasWork (indexName );
235231 assertUpgradeWorks (client (), indexName , version );
236232 assertPositionIncrementGapDefaults (indexName , version );
237233 assertAliasWithBadName (indexName , version );
238234 assertStoredBinaryFields (indexName , version );
239235 unloadIndex (indexName );
240236 }
241237
242- boolean findPayloadBoostInExplanation (Explanation expl ) {
243- if (expl .getDescription ().startsWith ("payloadBoost=" ) && expl .getValue () != 1f ) {
244- return true ;
245- } else {
246- boolean found = false ;
247- for (Explanation sub : expl .getDetails ()) {
248- found |= findPayloadBoostInExplanation (sub );
249- }
250- return found ;
251- }
252- }
253-
254- void assertAllSearchWorks (String indexName ) {
255- logger .info ("--> testing _all search" );
256- SearchResponse searchRsp = client ().prepareSearch (indexName ).get ();
257- ElasticsearchAssertions .assertNoFailures (searchRsp );
258- assertThat (searchRsp .getHits ().getTotalHits (), greaterThanOrEqualTo (1L ));
259- SearchHit bestHit = searchRsp .getHits ().getAt (0 );
260-
261- // Make sure there are payloads and they are taken into account for the score
262- // the 'string' field has a boost of 4 in the mappings so it should get a payload boost
263- String stringValue = (String ) bestHit .getSourceAsMap ().get ("string" );
264- assertNotNull (stringValue );
265- Explanation explanation = client ().prepareExplain (indexName , bestHit .getType (), bestHit .getId ())
266- .setQuery (QueryBuilders .matchQuery ("_all" , stringValue )).get ().getExplanation ();
267- assertTrue ("Could not find payload boost in explanation\n " + explanation , findPayloadBoostInExplanation (explanation ));
268-
269- // Make sure the query can run on the whole index
270- searchRsp = client ().prepareSearch (indexName ).setQuery (QueryBuilders .matchQuery ("_all" , stringValue )).setExplain (true ).get ();
271- ElasticsearchAssertions .assertNoFailures (searchRsp );
272- assertThat (searchRsp .getHits ().getTotalHits (), greaterThanOrEqualTo (1L ));
273- }
274-
275- void assertBasicAggregationWorks (String indexName ) {
276- // histogram on a long
277- SearchResponse searchRsp = client ().prepareSearch (indexName ).addAggregation (AggregationBuilders .histogram ("histo" ).field
278- ("long_sort" ).interval (10 )).get ();
279- ElasticsearchAssertions .assertSearchResponse (searchRsp );
280- Histogram histo = searchRsp .getAggregations ().get ("histo" );
281- assertNotNull (histo );
282- long totalCount = 0 ;
283- for (Histogram .Bucket bucket : histo .getBuckets ()) {
284- totalCount += bucket .getDocCount ();
285- }
286- assertEquals (totalCount , searchRsp .getHits ().getTotalHits ());
287-
288- // terms on a boolean
289- searchRsp = client ().prepareSearch (indexName ).addAggregation (AggregationBuilders .terms ("bool_terms" ).field ("bool" )).get ();
290- Terms terms = searchRsp .getAggregations ().get ("bool_terms" );
291- totalCount = 0 ;
292- for (Terms .Bucket bucket : terms .getBuckets ()) {
293- totalCount += bucket .getDocCount ();
294- }
295- assertEquals (totalCount , searchRsp .getHits ().getTotalHits ());
296- }
297-
298- void assertRealtimeGetWorks (String indexName ) {
299- assertAcked (client ().admin ().indices ().prepareUpdateSettings (indexName ).setSettings (Settings .builder ()
300- .put ("refresh_interval" , -1 )
301- .build ()));
302- SearchRequestBuilder searchReq = client ().prepareSearch (indexName ).setQuery (QueryBuilders .matchAllQuery ());
303- SearchHit hit = searchReq .get ().getHits ().getAt (0 );
304- String docId = hit .getId ();
305- // foo is new, it is not a field in the generated index
306- client ().prepareUpdate (indexName , "doc" , docId ).setDoc (Requests .INDEX_CONTENT_TYPE , "foo" , "bar" ).get ();
307- GetResponse getRsp = client ().prepareGet (indexName , "doc" , docId ).get ();
308- Map <String , Object > source = getRsp .getSourceAsMap ();
309- assertThat (source , Matchers .hasKey ("foo" ));
310-
311- assertAcked (client ().admin ().indices ().prepareUpdateSettings (indexName ).setSettings (Settings .builder ()
312- .put ("refresh_interval" , IndexSettings .DEFAULT_REFRESH_INTERVAL )
313- .build ()));
314- }
315-
316- void assertNewReplicasWork (String indexName ) throws Exception {
317- final int numReplicas = 1 ;
318- final long startTime = System .currentTimeMillis ();
319- logger .debug ("--> creating [{}] replicas for index [{}]" , numReplicas , indexName );
320- assertAcked (client ().admin ().indices ().prepareUpdateSettings (indexName ).setSettings (Settings .builder ()
321- .put ("number_of_replicas" , numReplicas )
322- ).execute ().actionGet ());
323- ensureGreen (TimeValue .timeValueMinutes (2 ), indexName );
324- logger .debug ("--> index [{}] is green, took [{}]" , indexName , TimeValue .timeValueMillis (System .currentTimeMillis () - startTime ));
325- logger .debug ("--> recovery status:\n {}" , XContentHelper .toString (client ().admin ().indices ().prepareRecoveries (indexName ).get ()));
326-
327- // TODO: do something with the replicas! query? index?
328- }
329-
330238 void assertPositionIncrementGapDefaults (String indexName , Version version ) throws Exception {
331239 client ().prepareIndex (indexName , "doc" , "position_gap_test" ).setSource ("string" , Arrays .asList ("one" , "two three" ))
332240 .setRefreshPolicy (RefreshPolicy .IMMEDIATE ).get ();
0 commit comments