Skip to content

Commit

Permalink
fix wildcard term & terms query & add YAML REST test (#15607) (#15682)
Browse files Browse the repository at this point in the history
* fix wildcard term & terms query & add YAML REST test

* add CHANGELOG

---------

(cherry picked from commit ad1df9e)

Signed-off-by: gesong.samuel <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: gesong.samuel <[email protected]>
(cherry picked from commit a737f83)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and gesong.samuel committed Sep 4, 2024
1 parent a3312b4 commit 32a046f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix split response processor not included in allowlist ([#15393](https://github.com/opensearch-project/OpenSearch/pull/15393))
- Fix unchecked cast in dynamic action map getter ([#15394](https://github.com/opensearch-project/OpenSearch/pull/15394))
- Fix null values indexed as "null" strings in flat_object field ([#14069](https://github.com/opensearch-project/OpenSearch/pull/14069))
- Fix terms query on wildcard field returns nothing ([#15607](https://github.com/opensearch-project/OpenSearch/pull/15607))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,13 @@ setup:
my_field:
value: ".*"
- match: { hits.total.value: 5 }
---
"terms query on wildcard field matches":
- do:
search:
index: test
body:
query:
terms: { my_field: ["AbCd"] }
- match: { hits.total.value: 1 }
- match: { hits.hits.0._id: "5" }
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower

@Override
public Query termQueryCaseInsensitive(Object value, QueryShardContext context) {
return wildcardQuery(value.toString(), MultiTermQuery.CONSTANT_SCORE_REWRITE, true, context);
return wildcardQuery(BytesRefs.toString(value), MultiTermQuery.CONSTANT_SCORE_REWRITE, true, context);

Check warning on line 638 in server/src/main/java/org/opensearch/index/mapper/WildcardFieldMapper.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L638 was not covered by tests
}

@Override
Expand All @@ -649,7 +649,7 @@ public Query termsQuery(List<?> values, QueryShardContext context) {
Set<String> expectedValues = new HashSet<>();
StringBuilder pattern = new StringBuilder();
for (Object value : values) {
String stringVal = value.toString();
String stringVal = BytesRefs.toString(value);

Check warning on line 652 in server/src/main/java/org/opensearch/index/mapper/WildcardFieldMapper.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L652 was not covered by tests
builder.add(matchAllTermsQuery(name(), getRequiredNGrams(stringVal)), BooleanClause.Occur.SHOULD);
expectedValues.add(stringVal);
if (pattern.length() > 0) {
Expand Down

0 comments on commit 32a046f

Please sign in to comment.