Skip to content

Commit

Permalink
NullPointer fix for field capabilities API (#76742)
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 committed Aug 23, 2021
1 parent 38fe33a commit 81e0bc2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 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 @@ -371,10 +371,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,
// 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);
responseMap.put(parentField, fieldCap);
}
}
dotIndex = parentField.lastIndexOf('.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.core.CheckedFunction;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexSortConfig;
Expand Down Expand Up @@ -365,6 +366,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 81e0bc2

Please sign in to comment.