Search in sources :

Example 1 with ScriptContext

use of org.elasticsearch.script.ScriptContext in project elasticsearch by elastic.

the class QueryShardContext method getLazySearchScript.

/**
     * Returns a lazily created {@link SearchScript} that is compiled immediately but can be pulled later once all
     * parameters are available.
     */
public final Function<Map<String, Object>, SearchScript> getLazySearchScript(Script script, ScriptContext context) {
    failIfFrozen();
    CompiledScript compile = scriptService.compile(script, context);
    return (p) -> scriptService.search(lookup(), compile, p);
}
Also used : CompiledScript(org.elasticsearch.script.CompiledScript) Query(org.apache.lucene.search.Query) BitsetFilterCache(org.elasticsearch.index.cache.bitset.BitsetFilterCache) Arrays(java.util.Arrays) LongSupplier(java.util.function.LongSupplier) ParsingException(org.elasticsearch.common.ParsingException) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) MapperQueryParser(org.apache.lucene.queryparser.classic.MapperQueryParser) Function(java.util.function.Function) ScriptContext(org.elasticsearch.script.ScriptContext) Strings(org.elasticsearch.common.Strings) NestedScope(org.elasticsearch.index.query.support.NestedScope) BitSetProducer(org.apache.lucene.search.join.BitSetProducer) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Similarity(org.apache.lucene.search.similarities.Similarity) Map(java.util.Map) IndexSettings(org.elasticsearch.index.IndexSettings) QueryParserSettings(org.apache.lucene.queryparser.classic.QueryParserSettings) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) SearchScript(org.elasticsearch.script.SearchScript) SearchLookup(org.elasticsearch.search.lookup.SearchLookup) ObjectMapper(org.elasticsearch.index.mapper.ObjectMapper) Script(org.elasticsearch.script.Script) SetOnce(org.apache.lucene.util.SetOnce) Mapper(org.elasticsearch.index.mapper.Mapper) Analyzer(org.apache.lucene.analysis.Analyzer) Client(org.elasticsearch.client.Client) Collection(java.util.Collection) IOException(java.io.IOException) TextFieldMapper(org.elasticsearch.index.mapper.TextFieldMapper) BytesReference(org.elasticsearch.common.bytes.BytesReference) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) CheckedFunction(org.elasticsearch.common.CheckedFunction) MapperService(org.elasticsearch.index.mapper.MapperService) Version(org.elasticsearch.Version) CompiledScript(org.elasticsearch.script.CompiledScript) IndexFieldData(org.elasticsearch.index.fielddata.IndexFieldData) Queries(org.elasticsearch.common.lucene.search.Queries) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) ExecutableScript(org.elasticsearch.script.ExecutableScript) ContentPath(org.elasticsearch.index.mapper.ContentPath) ScriptService(org.elasticsearch.script.ScriptService) IndexReader(org.apache.lucene.index.IndexReader)

Example 2 with ScriptContext

use of org.elasticsearch.script.ScriptContext in project elasticsearch by elastic.

the class AbstractSortTestCase method init.

@BeforeClass
public static void init() throws IOException {
    Path genericConfigFolder = createTempDir();
    Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(Environment.PATH_CONF_SETTING.getKey(), genericConfigFolder).build();
    Environment environment = new Environment(baseSettings);
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new TestEngineService()));
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    scriptService = new ScriptService(baseSettings, environment, new ResourceWatcherService(baseSettings, null), scriptEngineRegistry, scriptContextRegistry, scriptSettings) {

        @Override
        public CompiledScript compile(Script script, ScriptContext scriptContext) {
            return new CompiledScript(ScriptType.INLINE, "mockName", "test", script);
        }
    };
    SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
Also used : Path(java.nio.file.Path) ContentPath(org.elasticsearch.index.mapper.ContentPath) CompiledScript(org.elasticsearch.script.CompiledScript) NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) Script(org.elasticsearch.script.Script) CompiledScript(org.elasticsearch.script.CompiledScript) ScriptContext(org.elasticsearch.script.ScriptContext) ScriptContextRegistry(org.elasticsearch.script.ScriptContextRegistry) ScriptService(org.elasticsearch.script.ScriptService) ScriptSettings(org.elasticsearch.script.ScriptSettings) ScriptEngineRegistry(org.elasticsearch.script.ScriptEngineRegistry) Environment(org.elasticsearch.env.Environment) SearchModule(org.elasticsearch.search.SearchModule) TestEngineService(org.elasticsearch.script.ScriptServiceTests.TestEngineService) ResourceWatcherService(org.elasticsearch.watcher.ResourceWatcherService) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) Settings(org.elasticsearch.common.settings.Settings) ScriptSettings(org.elasticsearch.script.ScriptSettings) IndexSettings(org.elasticsearch.index.IndexSettings) BeforeClass(org.junit.BeforeClass)

Example 3 with ScriptContext

use of org.elasticsearch.script.ScriptContext in project elasticsearch by elastic.

the class QueryShardContext method getLazyExecutableScript.

/**
     * Returns a lazily created {@link ExecutableScript} that is compiled immediately but can be pulled later once all
     * parameters are available.
     */
public final Function<Map<String, Object>, ExecutableScript> getLazyExecutableScript(Script script, ScriptContext context) {
    failIfFrozen();
    CompiledScript executable = scriptService.compile(script, context);
    return (p) -> scriptService.executable(executable, p);
}
Also used : CompiledScript(org.elasticsearch.script.CompiledScript) Query(org.apache.lucene.search.Query) BitsetFilterCache(org.elasticsearch.index.cache.bitset.BitsetFilterCache) Arrays(java.util.Arrays) LongSupplier(java.util.function.LongSupplier) ParsingException(org.elasticsearch.common.ParsingException) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) MapperQueryParser(org.apache.lucene.queryparser.classic.MapperQueryParser) Function(java.util.function.Function) ScriptContext(org.elasticsearch.script.ScriptContext) Strings(org.elasticsearch.common.Strings) NestedScope(org.elasticsearch.index.query.support.NestedScope) BitSetProducer(org.apache.lucene.search.join.BitSetProducer) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) Similarity(org.apache.lucene.search.similarities.Similarity) Map(java.util.Map) IndexSettings(org.elasticsearch.index.IndexSettings) QueryParserSettings(org.apache.lucene.queryparser.classic.QueryParserSettings) NamedXContentRegistry(org.elasticsearch.common.xcontent.NamedXContentRegistry) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) SearchScript(org.elasticsearch.script.SearchScript) SearchLookup(org.elasticsearch.search.lookup.SearchLookup) ObjectMapper(org.elasticsearch.index.mapper.ObjectMapper) Script(org.elasticsearch.script.Script) SetOnce(org.apache.lucene.util.SetOnce) Mapper(org.elasticsearch.index.mapper.Mapper) Analyzer(org.apache.lucene.analysis.Analyzer) Client(org.elasticsearch.client.Client) Collection(java.util.Collection) IOException(java.io.IOException) TextFieldMapper(org.elasticsearch.index.mapper.TextFieldMapper) BytesReference(org.elasticsearch.common.bytes.BytesReference) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) CheckedFunction(org.elasticsearch.common.CheckedFunction) MapperService(org.elasticsearch.index.mapper.MapperService) Version(org.elasticsearch.Version) CompiledScript(org.elasticsearch.script.CompiledScript) IndexFieldData(org.elasticsearch.index.fielddata.IndexFieldData) Queries(org.elasticsearch.common.lucene.search.Queries) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) ExecutableScript(org.elasticsearch.script.ExecutableScript) ContentPath(org.elasticsearch.index.mapper.ContentPath) ScriptService(org.elasticsearch.script.ScriptService) IndexReader(org.apache.lucene.index.IndexReader)

Aggregations

NamedXContentRegistry (org.elasticsearch.common.xcontent.NamedXContentRegistry)3 IndexSettings (org.elasticsearch.index.IndexSettings)3 ContentPath (org.elasticsearch.index.mapper.ContentPath)3 CompiledScript (org.elasticsearch.script.CompiledScript)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections.unmodifiableMap (java.util.Collections.unmodifiableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Function (java.util.function.Function)2 LongSupplier (java.util.function.LongSupplier)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 IndexReader (org.apache.lucene.index.IndexReader)2 MapperQueryParser (org.apache.lucene.queryparser.classic.MapperQueryParser)2 QueryParserSettings (org.apache.lucene.queryparser.classic.QueryParserSettings)2 Query (org.apache.lucene.search.Query)2 BitSetProducer (org.apache.lucene.search.join.BitSetProducer)2 Similarity (org.apache.lucene.search.similarities.Similarity)2 SetOnce (org.apache.lucene.util.SetOnce)2