diff --git a/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java index 4e6906401351d..c3693f4ded9f3 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/IndexFieldMapper.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.search.Queries; -import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.IndexFieldData; @@ -38,7 +37,6 @@ import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.regex.Pattern; public class IndexFieldMapper extends MetadataFieldMapper { @@ -175,20 +173,6 @@ public Query prefixQuery(String value, } } - @Override - public Query regexpQuery(String value, int flags, int maxDeterminizedStates, - MultiTermQuery.RewriteMethod method, QueryShardContext context) { - String indexName = context.getFullyQualifiedIndex().getName(); - Pattern pattern = Regex.compile(value, Regex.flagsToString(flags)); - - if (pattern.matcher(indexName).matches()) { - return Queries.newMatchAllQuery(); - } else { - return Queries.newMatchNoDocsQuery("The index [" + context.getFullyQualifiedIndex().getName() - + "] doesn't match the provided pattern [" + value + "]."); - } - } - @Override public Query wildcardQuery(String value, @Nullable MultiTermQuery.RewriteMethod method, diff --git a/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldTypeTests.java b/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldTypeTests.java index 11b365ff16e2b..1b100fb0872ea 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldTypeTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/IndexFieldTypeTests.java @@ -27,9 +27,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.index.query.QueryShardException; import java.util.function.Predicate; +import static org.hamcrest.Matchers.containsString; + public class IndexFieldTypeTests extends FieldTypeTestCase { @Override @@ -46,22 +49,23 @@ public void testPrefixQuery() { assertEquals(new MatchNoDocsQuery(), ft.prefixQuery("other_ind", null, createContext())); } - public void testRegexpQuery() { + public void testWildcardQuery() { MappedFieldType ft = createDefaultFieldType(); ft.setName("field"); ft.setIndexOptions(IndexOptions.DOCS); - assertEquals(new MatchAllDocsQuery(), ft.regexpQuery("ind.x", 0, 10, null, createContext())); - assertEquals(new MatchNoDocsQuery(), ft.regexpQuery("ind?x", 0, 10, null, createContext())); + assertEquals(new MatchAllDocsQuery(), ft.wildcardQuery("ind*x", null, createContext())); + assertEquals(new MatchNoDocsQuery(), ft.wildcardQuery("other_ind*x", null, createContext())); } - public void testWildcardQuery() { + public void testRegexpQuery() { MappedFieldType ft = createDefaultFieldType(); ft.setName("field"); ft.setIndexOptions(IndexOptions.DOCS); - assertEquals(new MatchAllDocsQuery(), ft.wildcardQuery("ind*x", null, createContext())); - assertEquals(new MatchNoDocsQuery(), ft.wildcardQuery("other_ind*x", null, createContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> + assertEquals(new MatchAllDocsQuery(), ft.regexpQuery("ind.x", 0, 10, null, createContext()))); + assertThat(e.getMessage(), containsString("Can only use regexp queries on keyword and text fields")); } private QueryShardContext createContext() {