Skip to content

Commit f8b110e

Browse files
committed
Search - add case insensitive support for regex queries. (elastic#59441)
(Backport) Added case insensitive support for regex queries. Forks a copy of Lucene’s RegexpQuery and RegExp from Lucene master. This can be removed when 8.7 Lucene is released. Closes elastic#59235
1 parent f22ddf8 commit f8b110e

File tree

28 files changed

+1411
-96
lines changed

28 files changed

+1411
-96
lines changed

docs/reference/query-dsl/regexp-query.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ GET /_search
2828
"user.id": {
2929
"value": "k.*y",
3030
"flags": "ALL",
31+
"case_insensitive": true,
3132
"max_determinized_states": 10000,
3233
"rewrite": "constant_score"
3334
}
@@ -67,6 +68,10 @@ provided. To improve performance, avoid using wildcard patterns, such as `.*` or
6768
valid values and more information, see <<regexp-optional-operators, Regular
6869
expression syntax>>.
6970

71+
`case_insensitive`::
72+
(Optional, boolean) allows case insensitive matching of the regular expression
73+
value with the indexed field values when set to true. Setting to false is disallowed.
74+
7075
`max_determinized_states`::
7176
+
7277
--

plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public Query wildcardQuery(String value,
146146
}
147147

148148
@Override
149-
public Query regexpQuery(String value, int flags, int maxDeterminizedStates,
149+
public Query regexpQuery(String value, int syntaxFlags, int matchFlags, int maxDeterminizedStates,
150150
MultiTermQuery.RewriteMethod method, QueryShardContext context) {
151151
throw new UnsupportedOperationException("[regexp] queries are not supported on [" + CONTENT_TYPE + "] fields.");
152152
}

plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/CollationFieldTypeTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void testTermsQuery() {
9191
public void testRegexpQuery() {
9292
MappedFieldType ft = new CollationFieldType("field", DEFAULT_COLLATOR);
9393
UnsupportedOperationException e = expectThrows(UnsupportedOperationException.class,
94-
() -> ft.regexpQuery("foo.*", 0, 10, null, randomMockShardContext()));
94+
() -> ft.regexpQuery("foo.*", 0, 0, 10, null, randomMockShardContext()));
9595
assertEquals("[regexp] queries are not supported on [icu_collation_keyword] fields.", e.getMessage());
9696
}
9797

server/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,5 +333,8 @@ tasks.named("dependencyLicenses").configure {
333333
tasks.named("licenseHeaders").configure {
334334
// Ignore our vendored version of Google Guice
335335
excludes << 'org/elasticsearch/common/inject/**/*'
336+
// Ignore temporary copies of impending 8.7 Lucene classes
337+
excludes << 'org/apache/lucene/search/RegExp87*'
338+
excludes << 'org/apache/lucene/search/RegexpQuery87*'
336339
excludes << 'org/elasticsearch/client/documentation/placeholder.txt'
337-
}
340+
}

0 commit comments

Comments
 (0)