|
29 | 29 | import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
|
30 | 30 | import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
|
31 | 31 | import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder;
|
| 32 | +import org.elasticsearch.action.bulk.BulkResponse; |
| 33 | +import org.elasticsearch.action.index.IndexRequest; |
32 | 34 | import org.elasticsearch.action.search.SearchResponse;
|
33 | 35 | import org.elasticsearch.cluster.metadata.AliasMetaData;
|
34 | 36 | import org.elasticsearch.common.Priority;
|
@@ -604,38 +606,66 @@ public void testMultipleAliasesPrecedence() throws Exception {
|
604 | 606 | public void testStrictAliasParsingInIndicesCreatedViaTemplates() throws Exception {
|
605 | 607 | // Indexing into a should succeed, because the field mapping for field 'field' is defined in the test mapping.
|
606 | 608 | client().admin().indices().preparePutTemplate("template1")
|
607 |
| - .setTemplate("a") |
| 609 | + .setTemplate("a*") |
608 | 610 | .setOrder(0)
|
609 | 611 | .addMapping("test", "field", "type=string")
|
610 | 612 | .addAlias(new Alias("alias1").filter(termFilter("field", "value"))).get();
|
611 | 613 | // Indexing into b should succeed, because the field mapping for field 'field' is defined in the _default_ mapping and the test type exists.
|
612 | 614 | client().admin().indices().preparePutTemplate("template2")
|
613 |
| - .setTemplate("b") |
| 615 | + .setTemplate("b*") |
614 | 616 | .setOrder(0)
|
615 | 617 | .addMapping("_default_", "field", "type=string")
|
616 | 618 | .addMapping("test")
|
617 | 619 | .addAlias(new Alias("alias2").filter(termFilter("field", "value"))).get();
|
618 | 620 | // Indexing into c should succeed, because the field mapping for field 'field' is defined in the _default_ mapping.
|
619 | 621 | client().admin().indices().preparePutTemplate("template3")
|
620 |
| - .setTemplate("c") |
| 622 | + .setTemplate("c*") |
621 | 623 | .setOrder(0)
|
622 | 624 | .addMapping("_default_", "field", "type=string")
|
623 | 625 | .addAlias(new Alias("alias3").filter(termFilter("field", "value"))).get();
|
624 | 626 | // Indexing into d index should fail, since there is field with name 'field' in the mapping
|
625 | 627 | client().admin().indices().preparePutTemplate("template4")
|
626 |
| - .setTemplate("d") |
| 628 | + .setTemplate("d*") |
627 | 629 | .setOrder(0)
|
628 | 630 | .addAlias(new Alias("alias4").filter(termFilter("field", "value"))).get();
|
629 | 631 |
|
630 |
| - client().prepareIndex("a", "test", "test").setSource("{}").get(); |
631 |
| - client().prepareIndex("b", "test", "test").setSource("{}").get(); |
632 |
| - client().prepareIndex("c", "test", "test").setSource("{}").get(); |
| 632 | + client().prepareIndex("a1", "test", "test").setSource("{}").get(); |
| 633 | + BulkResponse response = client().prepareBulk().add(new IndexRequest("a2", "test", "test").source("{}")).get(); |
| 634 | + assertThat(response.hasFailures(), is(false)); |
| 635 | + assertThat(response.getItems()[0].isFailed(), equalTo(false)); |
| 636 | + assertThat(response.getItems()[0].getIndex(), equalTo("a2")); |
| 637 | + assertThat(response.getItems()[0].getType(), equalTo("test")); |
| 638 | + assertThat(response.getItems()[0].getId(), equalTo("test")); |
| 639 | + assertThat(response.getItems()[0].getVersion(), equalTo(1l)); |
| 640 | + |
| 641 | + client().prepareIndex("b1", "test", "test").setSource("{}").get(); |
| 642 | + response = client().prepareBulk().add(new IndexRequest("b2", "test", "test").source("{}")).get(); |
| 643 | + assertThat(response.hasFailures(), is(false)); |
| 644 | + assertThat(response.getItems()[0].isFailed(), equalTo(false)); |
| 645 | + assertThat(response.getItems()[0].getIndex(), equalTo("b2")); |
| 646 | + assertThat(response.getItems()[0].getType(), equalTo("test")); |
| 647 | + assertThat(response.getItems()[0].getId(), equalTo("test")); |
| 648 | + assertThat(response.getItems()[0].getVersion(), equalTo(1l)); |
| 649 | + |
| 650 | + client().prepareIndex("c1", "test", "test").setSource("{}").get(); |
| 651 | + response = client().prepareBulk().add(new IndexRequest("c2", "test", "test").source("{}")).get(); |
| 652 | + assertThat(response.hasFailures(), is(false)); |
| 653 | + assertThat(response.getItems()[0].isFailed(), equalTo(false)); |
| 654 | + assertThat(response.getItems()[0].getIndex(), equalTo("c2")); |
| 655 | + assertThat(response.getItems()[0].getType(), equalTo("test")); |
| 656 | + assertThat(response.getItems()[0].getId(), equalTo("test")); |
| 657 | + assertThat(response.getItems()[0].getVersion(), equalTo(1l)); |
| 658 | + |
633 | 659 | try {
|
634 |
| - client().prepareIndex("d", "test", "test").setSource("{}").get(); |
| 660 | + client().prepareIndex("d1", "test", "test").setSource("{}").get(); |
635 | 661 | fail();
|
636 | 662 | } catch (Exception e) {
|
637 | 663 | assertThat(ExceptionsHelper.unwrapCause(e), instanceOf(ElasticsearchIllegalArgumentException.class));
|
638 | 664 | assertThat(e.getMessage(), containsString("failed to parse filter for alias [alias4]"));
|
639 | 665 | }
|
| 666 | + response = client().prepareBulk().add(new IndexRequest("d2", "test", "test").source("{}")).get(); |
| 667 | + assertThat(response.hasFailures(), is(true)); |
| 668 | + assertThat(response.getItems()[0].isFailed(), equalTo(true)); |
| 669 | + assertThat(response.getItems()[0].getFailureMessage(), containsString("failed to parse filter for alias [alias4]")); |
640 | 670 | }
|
641 | 671 | }
|
0 commit comments