|
14 | 14 | import org.apache.logging.log4j.Level; |
15 | 15 | import org.elasticsearch.ElasticsearchException; |
16 | 16 | import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteUtils; |
| 17 | +import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; |
17 | 18 | import org.elasticsearch.action.fieldcaps.FieldCapabilities; |
18 | 19 | import org.elasticsearch.action.fieldcaps.FieldCapabilitiesFailure; |
19 | 20 | import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest; |
20 | 21 | import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse; |
21 | 22 | import org.elasticsearch.action.fieldcaps.TransportFieldCapabilitiesAction; |
22 | 23 | import org.elasticsearch.action.index.IndexRequestBuilder; |
23 | 24 | import org.elasticsearch.action.support.ActiveShardCount; |
| 25 | +import org.elasticsearch.action.support.IndicesOptions; |
24 | 26 | import org.elasticsearch.action.support.PlainActionFuture; |
25 | 27 | import org.elasticsearch.client.Cancellable; |
26 | 28 | import org.elasticsearch.client.Request; |
|
45 | 47 | import org.elasticsearch.index.query.SearchExecutionContext; |
46 | 48 | import org.elasticsearch.index.shard.IndexShard; |
47 | 49 | import org.elasticsearch.index.shard.ShardId; |
| 50 | +import org.elasticsearch.indices.IndexClosedException; |
48 | 51 | import org.elasticsearch.indices.IndicesService; |
49 | 52 | import org.elasticsearch.plugins.FieldPredicate; |
50 | 53 | import org.elasticsearch.plugins.MapperPlugin; |
@@ -319,6 +322,63 @@ public void testWithIndexAlias() { |
319 | 322 | assertEquals(response1, response2); |
320 | 323 | } |
321 | 324 |
|
| 325 | + public void testNoIndices() { |
| 326 | + boolean ignoreUnavailable = false; |
| 327 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 328 | + client().admin().indices().close(new CloseIndexRequest("old_index")).actionGet(); |
| 329 | + FieldCapabilitiesResponse response = client().prepareFieldCaps().setFields("*").setIndicesOptions(options).get(); |
| 330 | + assertIndices(response, "new_index"); |
| 331 | + } |
| 332 | + |
| 333 | + public void testNoIndicesIgnoreUnavailable() { |
| 334 | + boolean ignoreUnavailable = true; |
| 335 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 336 | + client().admin().indices().close(new CloseIndexRequest("old_index")).actionGet(); |
| 337 | + FieldCapabilitiesResponse response = client().prepareFieldCaps().setFields("*").setIndicesOptions(options).get(); |
| 338 | + assertIndices(response, "new_index"); |
| 339 | + } |
| 340 | + |
| 341 | + public void testOneClosedIndex() { |
| 342 | + boolean ignoreUnavailable = false; |
| 343 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 344 | + client().admin().indices().close(new CloseIndexRequest("old_index")).actionGet(); |
| 345 | + IndexClosedException ex = expectThrows( |
| 346 | + IndexClosedException.class, |
| 347 | + client().prepareFieldCaps("old_index").setFields("*").setIndicesOptions(options) |
| 348 | + ); |
| 349 | + assertEquals("closed", ex.getMessage()); |
| 350 | + } |
| 351 | + |
| 352 | + public void testOneClosedIndexIgnoreUnavailable() { |
| 353 | + boolean ignoreUnavailable = true; |
| 354 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 355 | + client().admin().indices().close(new CloseIndexRequest("old_index")).actionGet(); |
| 356 | + FieldCapabilitiesResponse response = client().prepareFieldCaps("old_index").setFields("*").setIndicesOptions(options).get(); |
| 357 | + assertIndices(response); |
| 358 | + } |
| 359 | + |
| 360 | + public void testTwoIndicesOneClosed() { |
| 361 | + boolean ignoreUnavailable = false; |
| 362 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 363 | + client().admin().indices().close(new CloseIndexRequest("old_index")).actionGet(); |
| 364 | + IndexClosedException ex = expectThrows( |
| 365 | + IndexClosedException.class, |
| 366 | + client().prepareFieldCaps("old_index", "new_index").setFields("*").setIndicesOptions(options) |
| 367 | + ); |
| 368 | + assertEquals("closed", ex.getMessage()); |
| 369 | + } |
| 370 | + |
| 371 | + public void testTwoIndicesOneClosedIgnoreUnavailable() { |
| 372 | + boolean ignoreUnavailable = true; |
| 373 | + IndicesOptions options = IndicesOptions.fromOptions(ignoreUnavailable, true, true, false, true, true, false, false); |
| 374 | + client().admin().indices().close(new CloseIndexRequest("old_index")).actionGet(); |
| 375 | + FieldCapabilitiesResponse response = client().prepareFieldCaps("old_index", "new_index") |
| 376 | + .setFields("*") |
| 377 | + .setIndicesOptions(options) |
| 378 | + .get(); |
| 379 | + assertIndices(response, "new_index"); |
| 380 | + } |
| 381 | + |
322 | 382 | public void testWithIndexFilter() throws InterruptedException { |
323 | 383 | assertAcked(prepareCreate("index-1").setMapping("timestamp", "type=date", "field1", "type=keyword")); |
324 | 384 | assertAcked(prepareCreate("index-2").setMapping("timestamp", "type=date", "field1", "type=long")); |
|
0 commit comments