Skip to content

Commit

Permalink
Fix allowUnmappedFields, mapUnmappedFieldAsString settings to be appl…
Browse files Browse the repository at this point in the history
…ied when parsing query string query (opensearch-project#13957) (opensearch-project#14876)

* Modify to invoke QueryShardContext.fieldMapper() method to apply allowUnmappedFields and mapUnmappedFieldAsString settings

* Add test cases to verify returning 400 responses if unmapped fields are included for some types of query

* Add changelog

---------

(cherry picked from commit 6227dc6)

Signed-off-by: imyp92 <pyw5420@gmail.com>
Signed-off-by: gaobinlong <gbinlong@amazon.com>
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: gaobinlong <gbinlong@amazon.com>
Signed-off-by: kkewwei <kkewwei@163.com>
  • Loading branch information
3 people authored and kkewwei committed Jul 24, 2024
1 parent 621432d commit b9e79c4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Remove query categorization changes ([#14759](https://github.com/opensearch-project/OpenSearch/pull/14759))

### Fixed
- Fix allowUnmappedFields, mapUnmappedFieldAsString settings are not applied when parsing certain types of query string query ([#13957](https://github.com/opensearch-project/OpenSearch/pull/13957))
- Fix bug in SBP cancellation logic ([#13259](https://github.com/opensearch-project/OpenSearch/pull/13474))
- Fix handling of Short and Byte data types in ScriptProcessor ingest pipeline ([#14379](https://github.com/opensearch-project/OpenSearch/issues/14379))
- Switch to iterative version of WKT format parser ([#14086](https://github.com/opensearch-project/OpenSearch/pull/14086))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,48 @@
index: documents_index
id: some_id
- match: { responses.0.hits.total: 1 }

- do:
catch: bad_request
index:
index: queries_index
body:
query:
query_string:
query: "unmapped: *"

- do:
catch: bad_request
index:
index: queries_index
body:
query:
query_string:
query: "_exists_: unmappedField"

- do:
catch: bad_request
index:
index: queries_index
body:
query:
query_string:
query: "unmappedField: <100"

- do:
catch: bad_request
index:
index: queries_index
body:
query:
query_string:
query: "unmappedField: test~"

- do:
catch: bad_request
index:
index: queries_index
body:
query:
query_string:
query: "unmappedField: test*"
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,16 @@ private static Collection<String> getMappedField(QueryShardContext context, Stri
if (context.getObjectMapper(fieldPattern) != null) {
// the _field_names field also indexes objects, so we don't have to
// do any more work to support exists queries on whole objects
fields = Collections.singleton(fieldPattern);
return Collections.singleton(fieldPattern);
} else {
fields = context.simpleMatchToIndexNames(fieldPattern);
}

if (fields.size() == 1) {
String field = fields.iterator().next();
MappedFieldType fieldType = context.getMapperService().fieldType(field);
MappedFieldType fieldType = context.fieldMapper(field);
if (fieldType == null) {
// The field does not exist as a leaf but could be an object so
// check for an object mapper
if (context.getObjectMapper(field) == null) {
return Collections.emptySet();
}
return Collections.emptySet();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static Map<String, Float> resolveMappingField(
fieldName = fieldName + fieldSuffix;
}

MappedFieldType fieldType = context.getMapperService().fieldType(fieldName);
MappedFieldType fieldType = context.fieldMapper(fieldName);
if (fieldType == null) {
fieldType = context.resolveDerivedFieldType(fieldName);
}
Expand Down

0 comments on commit b9e79c4

Please sign in to comment.