Skip to content

Commit

Permalink
Catch exceptions and log them while building derived source values
Browse files Browse the repository at this point in the history
  • Loading branch information
rayshrey committed Dec 30, 2024
1 parent 96f19c2 commit 6b079da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,9 @@ private GetResult innerGetLoadFromStoredFields(
builder.map(sourceAsMap);
source = BytesReference.bytes(builder);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
} catch (Exception ex) {
logger.error("Error while building source from doc values", ex);
//throw new RuntimeException(ex);
}


Expand Down
17 changes: 12 additions & 5 deletions server/src/main/java/org/opensearch/search/fetch/FetchPhase.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.opensearch.index.mapper.NumberFieldMapper;
import org.opensearch.index.mapper.ObjectMapper;
import org.opensearch.index.mapper.SourceFieldMapper;
import org.opensearch.index.recovery.RemoteStoreRestoreService;
import org.opensearch.index.shard.IndexShard;
import org.opensearch.search.DocValueFormat;
import org.opensearch.search.SearchContextSourcePrinter;
Expand Down Expand Up @@ -117,10 +118,12 @@ public class FetchPhase {
private static final Logger LOGGER = LogManager.getLogger(FetchPhase.class);

private final FetchSubPhase[] fetchSubPhases;
private static final Logger logger = LogManager.getLogger(FetchPhase.class);

public FetchPhase(List<FetchSubPhase> fetchSubPhases) {
this.fetchSubPhases = fetchSubPhases.toArray(new FetchSubPhase[fetchSubPhases.size() + 1]);
this.fetchSubPhases[fetchSubPhases.size()] = new InnerHitsPhase(this);

}

public void execute(SearchContext context) {
Expand Down Expand Up @@ -368,11 +371,15 @@ private HitContext prepareNonNestedHitContext(
HitContext hitContext = new HitContext(hit, subReaderContext, subDocId, lookup.source());
//if (fieldsVisitor.source() != null) {
hitContext.sourceLookup().setSource(fieldsVisitor.source());
Map<String, Object> sourceAsMap = buildUsingDocValues(docId, subReaderContext.reader(), context.mapperService(), context.indexShard());
sourceAsMap = unflatten(sourceAsMap);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
builder.map(sourceAsMap);
hitContext.sourceLookup().setSource(BytesReference.bytes(builder));
try {
Map<String, Object> sourceAsMap = buildUsingDocValues(docId, subReaderContext.reader(), context.mapperService(), context.indexShard());
sourceAsMap = unflatten(sourceAsMap);
try (XContentBuilder builder = XContentFactory.jsonBuilder()) {
builder.map(sourceAsMap);
hitContext.sourceLookup().setSource(BytesReference.bytes(builder));
}
} catch (Exception e) {
logger.error("Error while building source from doc values", e);
}
//}
return hitContext;
Expand Down

0 comments on commit 6b079da

Please sign in to comment.