diff --git a/core/src/main/java/org/opensearch/sql/utils/OperatorUtils.java b/core/src/main/java/org/opensearch/sql/utils/OperatorUtils.java index 26a21251eb..f4ece6a190 100644 --- a/core/src/main/java/org/opensearch/sql/utils/OperatorUtils.java +++ b/core/src/main/java/org/opensearch/sql/utils/OperatorUtils.java @@ -22,8 +22,9 @@ public class OperatorUtils { * @return if text matches pattern returns true; else return false. */ public static ExprBooleanValue matches(ExprValue text, ExprValue pattern) { - return ExprBooleanValue - .of(Pattern.compile(patternToRegex(pattern.stringValue())).matcher(text.stringValue()) + return ExprBooleanValue.of( + Pattern.compile(patternToRegex(pattern.stringValue()), Pattern.CASE_INSENSITIVE) + .matcher(text.stringValue()) .matches()); } diff --git a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LikeQuery.java b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LikeQuery.java index dbf0e5544c..ad47ba437a 100644 --- a/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LikeQuery.java +++ b/opensearch/src/main/java/org/opensearch/sql/opensearch/storage/script/filter/lucene/LikeQuery.java @@ -32,6 +32,6 @@ public QueryBuilder build(FunctionExpression func) { */ protected WildcardQueryBuilder createBuilder(String field, String query) { String matchText = StringUtils.convertSqlWildcardToLucene(query); - return QueryBuilders.wildcardQuery(field, matchText); + return QueryBuilders.wildcardQuery(field, matchText).caseInsensitive(true); } } diff --git a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java index cea4e2488a..f3e4fe7afd 100644 --- a/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java +++ b/opensearch/src/test/java/org/opensearch/sql/opensearch/storage/script/filter/FilterQueryBuilderTest.java @@ -132,6 +132,7 @@ void should_build_wildcard_query_for_like_expression() { + " \"wildcard\" : {\n" + " \"name\" : {\n" + " \"wildcard\" : \"*John?\",\n" + + " \"case_insensitive\" : true,\n" + " \"boost\" : 1.0\n" + " }\n" + " }\n" @@ -282,6 +283,7 @@ void should_use_keyword_for_multi_field_in_like_expression() { + " \"wildcard\" : {\n" + " \"name.keyword\" : {\n" + " \"wildcard\" : \"John*\",\n" + + " \"case_insensitive\" : true,\n" + " \"boost\" : 1.0\n" + " }\n" + " }\n"