Skip to content

Commit ed66587

Browse files
fix wildcard term & terms query & add YAML REST test (#15607) (#15682) (#15706)
1 parent 0fd6a6a commit ed66587

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
100100
- Fix split response processor not included in allowlist ([#15393](https://github.com/opensearch-project/OpenSearch/pull/15393))
101101
- Fix unchecked cast in dynamic action map getter ([#15394](https://github.com/opensearch-project/OpenSearch/pull/15394))
102102
- Fix null values indexed as "null" strings in flat_object field ([#14069](https://github.com/opensearch-project/OpenSearch/pull/14069))
103+
- Fix terms query on wildcard field returns nothing ([#15607](https://github.com/opensearch-project/OpenSearch/pull/15607))
103104

104105
### Security
105106

rest-api-spec/src/main/resources/rest-api-spec/test/search/270_wildcard_fieldtype_queries.yml

+10
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,13 @@ setup:
227227
my_field:
228228
value: ".*"
229229
- match: { hits.total.value: 5 }
230+
---
231+
"terms query on wildcard field matches":
232+
- do:
233+
search:
234+
index: test
235+
body:
236+
query:
237+
terms: { my_field: ["AbCd"] }
238+
- match: { hits.total.value: 1 }
239+
- match: { hits.hits.0._id: "5" }

server/src/main/java/org/opensearch/index/mapper/WildcardFieldMapper.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower
635635

636636
@Override
637637
public Query termQueryCaseInsensitive(Object value, QueryShardContext context) {
638-
return wildcardQuery(value.toString(), MultiTermQuery.CONSTANT_SCORE_REWRITE, true, context);
638+
return wildcardQuery(BytesRefs.toString(value), MultiTermQuery.CONSTANT_SCORE_REWRITE, true, context);
639639
}
640640

641641
@Override
@@ -649,7 +649,7 @@ public Query termsQuery(List<?> values, QueryShardContext context) {
649649
Set<String> expectedValues = new HashSet<>();
650650
StringBuilder pattern = new StringBuilder();
651651
for (Object value : values) {
652-
String stringVal = value.toString();
652+
String stringVal = BytesRefs.toString(value);
653653
builder.add(matchAllTermsQuery(name(), getRequiredNGrams(stringVal)), BooleanClause.Occur.SHOULD);
654654
expectedValues.add(stringVal);
655655
if (pattern.length() > 0) {

0 commit comments

Comments
 (0)