|
57 | 57 | import org.opensearch.plugins.Plugin;
|
58 | 58 | import org.opensearch.search.SearchHit;
|
59 | 59 | import org.opensearch.search.SearchHits;
|
60 |
| -import org.opensearch.search.SearchModule; |
| 60 | +import org.opensearch.search.SearchService; |
61 | 61 | import org.opensearch.search.builder.SearchSourceBuilder;
|
62 | 62 | import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;
|
63 | 63 | import org.junit.BeforeClass;
|
|
79 | 79 | import static org.opensearch.index.query.QueryBuilders.simpleQueryStringQuery;
|
80 | 80 | import static org.opensearch.index.query.QueryBuilders.termQuery;
|
81 | 81 | import static org.opensearch.search.SearchService.CLUSTER_CONCURRENT_SEGMENT_SEARCH_SETTING;
|
| 82 | +import static org.opensearch.search.SearchService.INDICES_MAX_CLAUSE_COUNT_SETTING; |
82 | 83 | import static org.opensearch.test.StreamsUtils.copyToStringFromClasspath;
|
83 | 84 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
|
84 | 85 | import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertFailures;
|
@@ -122,7 +123,7 @@ public static void createRandomClusterSetting() {
|
122 | 123 | protected Settings nodeSettings(int nodeOrdinal) {
|
123 | 124 | return Settings.builder()
|
124 | 125 | .put(super.nodeSettings(nodeOrdinal))
|
125 |
| - .put(SearchModule.INDICES_MAX_CLAUSE_COUNT_SETTING.getKey(), CLUSTER_MAX_CLAUSE_COUNT) |
| 126 | + .put(SearchService.INDICES_MAX_CLAUSE_COUNT_SETTING.getKey(), CLUSTER_MAX_CLAUSE_COUNT) |
126 | 127 | .build();
|
127 | 128 | }
|
128 | 129 |
|
@@ -720,6 +721,52 @@ public void testFieldAliasOnDisallowedFieldType() throws Exception {
|
720 | 721 | assertHits(response.getHits(), "1");
|
721 | 722 | }
|
722 | 723 |
|
| 724 | + public void testDynamicClauseCountUpdate() throws Exception { |
| 725 | + client().prepareIndex("testdynamic").setId("1").setSource("field", "foo bar baz").get(); |
| 726 | + assertAcked( |
| 727 | + client().admin() |
| 728 | + .cluster() |
| 729 | + .prepareUpdateSettings() |
| 730 | + .setTransientSettings(Settings.builder().put(INDICES_MAX_CLAUSE_COUNT_SETTING.getKey(), CLUSTER_MAX_CLAUSE_COUNT - 1)) |
| 731 | + ); |
| 732 | + refresh(); |
| 733 | + StringBuilder sb = new StringBuilder("foo"); |
| 734 | + |
| 735 | + // create clause_count + 1 clauses to hit error |
| 736 | + for (int i = 0; i <= CLUSTER_MAX_CLAUSE_COUNT; i++) { |
| 737 | + sb.append(" OR foo" + i); |
| 738 | + } |
| 739 | + |
| 740 | + QueryStringQueryBuilder qb = queryStringQuery(sb.toString()).field("field"); |
| 741 | + |
| 742 | + SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () -> { |
| 743 | + client().prepareSearch("testdynamic").setQuery(qb).get(); |
| 744 | + }); |
| 745 | + |
| 746 | + assert (e.getDetailedMessage().contains("maxClauseCount is set to " + (CLUSTER_MAX_CLAUSE_COUNT - 1))); |
| 747 | + |
| 748 | + // increase clause count by 2 |
| 749 | + assertAcked( |
| 750 | + client().admin() |
| 751 | + .cluster() |
| 752 | + .prepareUpdateSettings() |
| 753 | + .setTransientSettings(Settings.builder().put(INDICES_MAX_CLAUSE_COUNT_SETTING.getKey(), CLUSTER_MAX_CLAUSE_COUNT + 2)) |
| 754 | + ); |
| 755 | + |
| 756 | + Thread.sleep(1); |
| 757 | + |
| 758 | + SearchResponse response = client().prepareSearch("testdynamic").setQuery(qb).get(); |
| 759 | + assertHitCount(response, 1); |
| 760 | + assertHits(response.getHits(), "1"); |
| 761 | + |
| 762 | + assertAcked( |
| 763 | + client().admin() |
| 764 | + .cluster() |
| 765 | + .prepareUpdateSettings() |
| 766 | + .setTransientSettings(Settings.builder().putNull(INDICES_MAX_CLAUSE_COUNT_SETTING.getKey())) |
| 767 | + ); |
| 768 | + } |
| 769 | + |
723 | 770 | private void assertHits(SearchHits hits, String... ids) {
|
724 | 771 | assertThat(hits.getTotalHits().value, equalTo((long) ids.length));
|
725 | 772 | Set<String> hitIds = new HashSet<>();
|
|
0 commit comments