Skip to content

Commit 501d8f9

Browse files
jed326Jay Deng
authored andcommitted
Use cached SourceLookup for FieldScript
Signed-off-by: Jay Deng <[email protected]>
1 parent 0930403 commit 501d8f9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

server/src/main/java/org/opensearch/script/FieldScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public abstract class FieldScript {
7878
private final LeafSearchLookup leafLookup;
7979

8080
public FieldScript(Map<String, Object> params, SearchLookup lookup, LeafReaderContext leafContext) {
81-
this.leafLookup = lookup.getLeafSearchLookup(leafContext);
81+
this.leafLookup = lookup.getLeafSearchLookupWithCachedSourceLookup(leafContext);
8282
params = new HashMap<>(params);
8383
params.putAll(leafLookup.asMap());
8484
this.params = new DynamicMap(params, PARAMS_FUNCTIONS);

server/src/main/java/org/opensearch/search/lookup/SearchLookup.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ public LeafSearchLookup getLeafSearchLookup(LeafReaderContext context) {
165165
);
166166
}
167167

168+
/**
169+
* Creates a new LeafSearchLookup using the existing sourceLookup. This is to be used in cases where multiple script instances are processing the same document (non-concurrently).
170+
*/
171+
public LeafSearchLookup getLeafSearchLookupWithCachedSourceLookup(LeafReaderContext context) {
172+
return new LeafSearchLookup(context, docMap.getLeafDocLookup(context), sourceLookup, fieldsLookup.getLeafFieldsLookup(context));
173+
}
174+
168175
public DocLookup doc() {
169176
return docMap;
170177
}

0 commit comments

Comments
 (0)