Skip to content

Commit e2e52bb

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

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-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+
- Honor COMPLEMENT for Regexp queries ([#18640](https://github.com/opensearch-project/OpenSearch/pull/18640))
3940

4041

4142
### Security

gradle/run.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ testClusters {
5252
}
5353
}
5454
}
55+
setting 'logger.level', 'DEBUG'
5556
}
5657

5758
}

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: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ 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+
};
67+
flags.add(randomFrom(availableFlags));
5968
}
6069
query.flags(flags.toArray(new RegexpFlag[0]));
6170
}
@@ -162,4 +171,32 @@ public void testParseFailsWithMultipleFields() throws IOException {
162171
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
163172
assertEquals("[regexp] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
164173
}
174+
175+
// Test that COMPLEMENT flag triggers deprecation warning
176+
public void testComplementFlagDeprecation() throws IOException {
177+
RegexpQueryBuilder query = new RegexpQueryBuilder("field", "a~bc");
178+
query.flags(RegexpFlag.COMPLEMENT);
179+
QueryShardContext context = createShardContext();
180+
Query luceneQuery = query.toQuery(context);
181+
assertNotNull(luceneQuery);
182+
assertThat(luceneQuery, instanceOf(RegexpQuery.class));
183+
assertWarnings(
184+
"The complement operator (~) for arbitrary patterns in regexp queries is deprecated " +
185+
"and will be removed in a future version. Consider rewriting your query to use character class negation [^...] or other query types."
186+
);
187+
}
188+
189+
// Separate test for COMPLEMENT flag Cacheability
190+
public void testComplementFlagCacheability() throws IOException {
191+
RegexpQueryBuilder queryBuilder = new RegexpQueryBuilder("field", "pattern");
192+
queryBuilder.flags(RegexpFlag.COMPLEMENT);
193+
QueryShardContext context = createShardContext();
194+
QueryBuilder rewriteQuery = rewriteQuery(queryBuilder, new QueryShardContext(context));
195+
assertNotNull(rewriteQuery.toQuery(context));
196+
assertTrue("query should be cacheable: " + queryBuilder, context.isCacheable());
197+
assertWarnings(
198+
"The complement operator (~) for arbitrary patterns in regexp queries is deprecated " +
199+
"and will be removed in a future version. Consider rewriting your query to use character class negation [^...] or other query types."
200+
);
201+
}
165202
}

0 commit comments

Comments
 (0)