Skip to content

Commit

Permalink
NullPointer fix for field capabilities API #76742 (#76813)
Browse files Browse the repository at this point in the history
Composite runtime fields do not have a mapped type - add null check, test and Nullable annotation to SearchExecutionContext.getObjectMapper(name)

Closes #76716
  • Loading branch information
markharwood authored Aug 23, 2021
1 parent ac6c1b3 commit 5ae0090
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,19 @@ query:
- match: {aggregations.response.buckets.0.doc_count: 5 }
- match: {aggregations.response.buckets.1.key: 304 }
- match: {aggregations.response.buckets.1.doc_count: 1 }

---
"Field caps with composite runtime mappings section. Issue 76742":

- skip:
version: " - 7.14.99"
reason: Composite Runtime mappings support was added in 7.15

- do:
field_caps:
index: http_logs
fields: "*"

- match: {indices: ["http_logs"]}
- match: {fields.http\.response.long.type: long}
- match: {fields.http\.clientip.ip.type: ip}
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ private FieldCapabilitiesIndexResponse shardOperation(final FieldCapabilitiesInd
if (searchExecutionContext.getFieldType(parentField) == null) {
// no field type, it must be an object field
ObjectMapper mapper = searchExecutionContext.getObjectMapper(parentField);
String type = mapper.isNested() ? "nested" : "object";
IndexFieldCapabilities fieldCap = new IndexFieldCapabilities(parentField, type,
false, false, false, Collections.emptyMap());
responseMap.put(parentField, fieldCap);
// Composite runtime fields do not have a mapped type for the root - check for null
if (mapper != null) {
String type = mapper.isNested() ? "nested" : "object";
IndexFieldCapabilities fieldCap = new IndexFieldCapabilities(parentField, type,
false, false, false, Collections.emptyMap());
responseMap.put(parentField, fieldCap);
}
}
dotIndex = parentField.lastIndexOf('.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexSortConfig;
Expand Down Expand Up @@ -383,6 +384,12 @@ private MappedFieldType fieldType(String name) {
return fieldType == null ? mappingLookup.getFieldType(name) : fieldType;
}

/**
*
* @param name name of the object
* @return can be null e.g. if field is root of a composite runtime field
*/
@Nullable
public ObjectMapper getObjectMapper(String name) {
return mappingLookup.objectMappers().get(name);
}
Expand Down

0 comments on commit 5ae0090

Please sign in to comment.