Skip to content

Commit

Permalink
handle null mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Dec 19, 2024
1 parent 04aaebf commit 9b093bd
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static boolean executeBulkItemRequest(
}

private static String[] getStoredFieldsSpec(IndexShard indexShard) {
if (InferenceMetadataFieldsMapper.isEnabled(indexShard.mapperService().mappingLookup().getMapping())) {
if (InferenceMetadataFieldsMapper.isEnabled(indexShard.mapperService().mappingLookup())) {
if (indexShard.mapperService().mappingLookup().inferenceFields().size() > 0) {
// Retrieves the inference metadata field containing the inference results for all semantic fields defined in the mapping.
return new String[] { RoutingFieldMapper.NAME, InferenceMetadataFieldsMapper.NAME };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ private static UpdateHelper.Result deleteInferenceResults(
MappingLookup mappingLookup
) {
if (result.getResponseResult() != DocWriteResponse.Result.UPDATED
|| InferenceMetadataFieldsMapper.isEnabled(mappingLookup.getMapping())) {
|| InferenceMetadataFieldsMapper.isEnabled(mappingLookup)) {
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public static boolean isEnabled(Settings settings) {
* This indicates whether the new format for semantic text fields is active by verifying the existence
* of the {@link InferenceMetadataFieldsMapper} in the mapping's metadata.
*
* @param mapping the mapping to evaluate
* @param mappingLookup the mapping to evaluate
* @return {@code true} if the {@link InferenceMetadataFieldsMapper} is present; {@code false} otherwise
*/
public static boolean isEnabled(Mapping mapping) {
return mapping.getMetadataMapperByName(InferenceMetadataFieldsMapper.NAME) != null;
public static boolean isEnabled(MappingLookup mappingLookup) {
return mappingLookup != null && mappingLookup.getMapping().getMetadataMapperByName(InferenceMetadataFieldsMapper.NAME) != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public BytesReference applyFilters(
}
var modSourceFilter = sourceFilter;
if (context != null
&& InferenceMetadataFieldsMapper.isEnabled(context.mappingLookup().getMapping())
&& InferenceMetadataFieldsMapper.isEnabled(context.mappingLookup())
&& context.mappingLookup().inferenceFields().isEmpty() == false) {
String[] modExcludes = new String[excludes != null ? excludes.length + 1 : 1];
if (excludes != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ private void hitExecute(HitContext hitContext) {
* to the original _source if it has been requested.
*/
private Source replaceInferenceMetadataFields(SearchHit hit, Source source) {
if (InferenceMetadataFieldsMapper.isEnabled(
fetchContext.getSearchExecutionContext().getMappingLookup().getMapping()
) == false) {
if (InferenceMetadataFieldsMapper.isEnabled(fetchContext.getSearchExecutionContext().getMappingLookup()) == false) {
return source;
}

Expand Down

0 comments on commit 9b093bd

Please sign in to comment.