Skip to content

Commit b445a49

Browse files
Update changelog
Signed-off-by: Prudhvi Godithi <pgodithi@amazon.com>
1 parent b0563ad commit b445a49

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
3636
- [Autotagging] Fix delete rule event consumption in InMemoryRuleProcessingService ([#18628](https://github.com/opensearch-project/OpenSearch/pull/18628))
3737
- Cannot communicate with HTTP/2 when reactor-netty is enabled ([#18599](https://github.com/opensearch-project/OpenSearch/pull/18599))
3838
- Fix the visit of sub queries for HasParentQuery and HasChildQuery ([#18621](https://github.com/opensearch-project/OpenSearch/pull/18621))
39+
- Fix the backward compatibility regression with COMPLEMENT for Regexp queries introduced in OpenSearch 3.0 ([#18640](https://github.com/opensearch-project/OpenSearch/pull/18640))
3940

4041

4142
### Security

server/src/main/java/org/opensearch/index/query/RegexpQueryBuilder.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.lucene.search.RegexpQuery;
3939
import org.apache.lucene.util.automaton.Operations;
4040
import org.apache.lucene.util.automaton.RegExp;
41+
import org.opensearch.common.logging.DeprecationLogger;
4142
import org.opensearch.common.lucene.BytesRefs;
4243
import org.opensearch.common.xcontent.LoggingDeprecationHandler;
4344
import org.opensearch.core.ParseField;
@@ -60,6 +61,9 @@
6061
* @opensearch.internal
6162
*/
6263
public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder> implements MultiTermQueryBuilder {
64+
65+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RegexpQueryBuilder.class);
66+
6367
public static final String NAME = "regexp";
6468

6569
public static final int DEFAULT_FLAGS_VALUE = RegexpFlag.ALL.value();
@@ -294,6 +298,18 @@ protected Query doToQuery(QueryShardContext context) throws QueryShardException,
294298
+ "] index level setting."
295299
);
296300
}
301+
302+
// Check if COMPLEMENT flag is being used
303+
// The COMPLEMENT flag maps to Lucene's DEPRECATED_COMPLEMENT which is marked for removal in Lucene 11
304+
// This deprecation warning helps users migrate their queries before the feature is completely removed
305+
if ((syntaxFlagsValue & RegexpFlag.COMPLEMENT.value()) != 0) {
306+
deprecationLogger.deprecate(
307+
"regexp_complement_operator",
308+
"The complement operator (~) for arbitrary patterns in regexp queries is deprecated and will be removed in a future version. "
309+
+ "Consider rewriting your query to use character class negation [^...] or other query types."
310+
);
311+
}
312+
297313
MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE);
298314

299315
int matchFlagsValue = caseInsensitive ? RegExp.ASCII_CASE_INSENSITIVE : 0;

server/src/test/java/org/opensearch/index/query/RegexpQueryBuilderTests.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@ protected RegexpQueryBuilder doCreateTestQueryBuilder() {
5555
List<RegexpFlag> flags = new ArrayList<>();
5656
int iter = randomInt(5);
5757
for (int i = 0; i < iter; i++) {
58-
flags.add(randomFrom(RegexpFlag.values()));
58+
// Exclude COMPLEMENT from random selection to avoid deprecation warnings
59+
RegexpFlag[] availableFlags = {
60+
RegexpFlag.INTERSECTION,
61+
RegexpFlag.EMPTY,
62+
RegexpFlag.ANYSTRING,
63+
RegexpFlag.INTERVAL,
64+
RegexpFlag.NONE,
65+
RegexpFlag.ALL };
66+
flags.add(randomFrom(availableFlags));
5967
}
6068
query.flags(flags.toArray(new RegexpFlag[0]));
6169
}
@@ -162,4 +170,32 @@ public void testParseFailsWithMultipleFields() throws IOException {
162170
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
163171
assertEquals("[regexp] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
164172
}
173+
174+
// Test that COMPLEMENT flag triggers deprecation warning
175+
public void testComplementFlagDeprecation() throws IOException {
176+
RegexpQueryBuilder query = new RegexpQueryBuilder("field", "a~bc");
177+
query.flags(RegexpFlag.COMPLEMENT);
178+
QueryShardContext context = createShardContext();
179+
Query luceneQuery = query.toQuery(context);
180+
assertNotNull(luceneQuery);
181+
assertThat(luceneQuery, instanceOf(RegexpQuery.class));
182+
assertWarnings(
183+
"The complement operator (~) for arbitrary patterns in regexp queries is deprecated "
184+
+ "and will be removed in a future version. Consider rewriting your query to use character class negation [^...] or other query types."
185+
);
186+
}
187+
188+
// Separate test for COMPLEMENT flag Cacheability
189+
public void testComplementFlagCacheability() throws IOException {
190+
RegexpQueryBuilder queryBuilder = new RegexpQueryBuilder("field", "pattern");
191+
queryBuilder.flags(RegexpFlag.COMPLEMENT);
192+
QueryShardContext context = createShardContext();
193+
QueryBuilder rewriteQuery = rewriteQuery(queryBuilder, new QueryShardContext(context));
194+
assertNotNull(rewriteQuery.toQuery(context));
195+
assertTrue("query should be cacheable: " + queryBuilder, context.isCacheable());
196+
assertWarnings(
197+
"The complement operator (~) for arbitrary patterns in regexp queries is deprecated "
198+
+ "and will be removed in a future version. Consider rewriting your query to use character class negation [^...] or other query types."
199+
);
200+
}
165201
}

0 commit comments

Comments
 (0)