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)

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

Signed-off-by: imyp92 <pyw5420@gmail.com>

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

Signed-off-by: imyp92 <pyw5420@gmail.com>

* Add changelog

Signed-off-by: imyp92 <pyw5420@gmail.com>

---------

Signed-off-by: imyp92 <pyw5420@gmail.com>
Signed-off-by: gaobinlong <gbinlong@amazon.com>
Co-authored-by: gaobinlong <gbinlong@amazon.com>
  • Loading branch information
2 people authored and harshavamsi committed Aug 20, 2024
1 parent 156e68c commit 05cbeea
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 @@ -64,6 +64,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 05cbeea

Please sign in to comment.