|
@@ -490,6 +490,46 @@ public class SimpleSearchIT extends ESIntegTestCase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ public void testTooLongPrefixInPrefixQuery() throws Exception {
|
|
|
+ createIndex("idx");
|
|
|
+
|
|
|
+ // Ensure the field `num` exists in the mapping
|
|
|
+ client().admin()
|
|
|
+ .indices()
|
|
|
+ .preparePutMapping("idx")
|
|
|
+ .setSource("{\"properties\":{\"num\":{\"type\":\"keyword\"}}}", XContentType.JSON)
|
|
|
+ .get();
|
|
|
+
|
|
|
+ // Index a simple document to ensure the field `num` is in the index
|
|
|
+ indexRandom(true, prepareIndex("idx").setSource("{\"num\":\"test\"}", XContentType.JSON));
|
|
|
+
|
|
|
+ int defaultMaxRegexLength = IndexSettings.MAX_REGEX_LENGTH_SETTING.get(Settings.EMPTY);
|
|
|
+ StringBuilder prefix = new StringBuilder(defaultMaxRegexLength);
|
|
|
+
|
|
|
+ while (prefix.length() <= defaultMaxRegexLength) {
|
|
|
+ prefix.append("a");
|
|
|
+ }
|
|
|
+
|
|
|
+ SearchPhaseExecutionException e = expectThrows(
|
|
|
+ SearchPhaseExecutionException.class,
|
|
|
+ () -> client().prepareSearch("idx").setQuery(QueryBuilders.prefixQuery("num", prefix.toString())).get()
|
|
|
+ );
|
|
|
+ assertThat(
|
|
|
+ e.getRootCause().getMessage(),
|
|
|
+ containsString(
|
|
|
+ "The length of prefix ["
|
|
|
+ + prefix.length()
|
|
|
+ + "] used in the Prefix Query request has exceeded "
|
|
|
+ + "the allowed maximum of ["
|
|
|
+ + defaultMaxRegexLength
|
|
|
+ + "]. "
|
|
|
+ + "This maximum can be set by changing the ["
|
|
|
+ + IndexSettings.MAX_REGEX_LENGTH_SETTING.getKey()
|
|
|
+ + "] index level setting."
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
public void testStrictlyCountRequest() throws Exception {
|
|
|
createIndex("test_count_1");
|
|
|
indexRandom(
|