Synthetic source error on script loads (#88334)

* Source Lookup refactor with error on script synthetic source load

Refactors SourceLookup into a static source lookup used for most cases where we
access the source again after the fetch phase, and a re-loading lookup used by
scripts. The re-loading lookup now also fails with an error when we are using
synthetic source preventing silent failures or non-sensical behavior from
scripts.
This commit is contained in:
tmgordeeva 2022-08-26 11:32:53 -07:00 committed by GitHub
parent 6f5fa14df0
commit db5ddb321f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
63 changed files with 520 additions and 220 deletions

View file

@ -15,6 +15,7 @@ import org.elasticsearch.index.mapper.NumberFieldMapper;
import org.elasticsearch.script.FieldScript;
import org.elasticsearch.script.ScriptException;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.search.lookup.SourceLookup;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
@ -49,7 +50,11 @@ public class ExpressionFieldScriptTests extends ESTestCase {
when(fieldData.load(any())).thenReturn(atomicFieldData);
service = new ExpressionScriptEngine();
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, _lookup, fdt) -> fieldData);
lookup = new SearchLookup(
field -> field.equals("field") ? fieldType : null,
(ignored, _lookup, fdt) -> fieldData,
new SourceLookup.ReaderSourceProvider()
);
}
private FieldScript.LeafFactory compile(String expression) {

View file

@ -17,6 +17,7 @@ import org.elasticsearch.script.DocValuesDocReader;
import org.elasticsearch.script.NumberSortScript;
import org.elasticsearch.script.ScriptException;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.search.lookup.SourceLookup;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
@ -50,7 +51,11 @@ public class ExpressionNumberSortScriptTests extends ESTestCase {
when(fieldData.load(any())).thenReturn(atomicFieldData);
service = new ExpressionScriptEngine();
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, _lookup, fdt) -> fieldData);
lookup = new SearchLookup(
field -> field.equals("field") ? fieldType : null,
(ignored, _lookup, fdt) -> fieldData,
new SourceLookup.ReaderSourceProvider()
);
}
private NumberSortScript.LeafFactory compile(String expression) {

View file

@ -16,6 +16,7 @@ import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
import org.elasticsearch.script.ScriptException;
import org.elasticsearch.script.TermsSetQueryScript;
import org.elasticsearch.search.lookup.SearchLookup;
import org.elasticsearch.search.lookup.SourceLookup;
import org.elasticsearch.test.ESTestCase;
import java.io.IOException;
@ -49,7 +50,11 @@ public class ExpressionTermsSetQueryTests extends ESTestCase {
when(fieldData.load(any())).thenReturn(atomicFieldData);
service = new ExpressionScriptEngine();
lookup = new SearchLookup(field -> field.equals("field") ? fieldType : null, (ignored, _lookup, fdt) -> fieldData);
lookup = new SearchLookup(
field -> field.equals("field") ? fieldType : null,
(ignored, _lookup, fdt) -> fieldData,
new SourceLookup.ReaderSourceProvider()
);
}
private TermsSetQueryScript.LeafFactory compile(String expression) {