當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptService類代碼示例

本文整理匯總了Java中org.elasticsearch.script.ScriptService的典型用法代碼示例。如果您正苦於以下問題:Java ScriptService類的具體用法?Java ScriptService怎麽用?Java ScriptService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ScriptService類屬於org.elasticsearch.script包,在下文中一共展示了ScriptService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testFactoryInvalidateWithInvalidCompiledScript

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
public void testFactoryInvalidateWithInvalidCompiledScript() throws Exception {
    String randomType = randomFrom("inline", "file", "id");
    ScriptService mockedScriptService = mock(ScriptService.class);
    ScriptException thrownException = new ScriptException("compile-time exception", new RuntimeException(),
        Collections.emptyList(), "script", "mockscript");
    when(mockedScriptService.compile(any(), any())).thenThrow(thrownException);
    factory = new ScriptProcessor.Factory(mockedScriptService);

    Map<String, Object> configMap = new HashMap<>();
    configMap.put("lang", "mockscript");
    configMap.put(randomType, "my_script");

    ElasticsearchException exception = expectThrows(ElasticsearchException.class,
        () -> factory.create(null, randomAsciiOfLength(10), configMap));

    assertThat(exception.getMessage(), is("compile-time exception"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:ScriptProcessorFactoryTests.java

示例2: nodeSettings

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
/**
 * This method is used to obtain settings for the <tt>Nth</tt> node in the cluster.
 * Nodes in this cluster are associated with an ordinal number such that nodes can
 * be started with specific configurations. This method might be called multiple
 * times with the same ordinal and is expected to return the same value for each invocation.
 * In other words subclasses must ensure this method is idempotent.
 */
protected Settings nodeSettings(int nodeOrdinal) {
    Settings.Builder builder = Settings.builder()
        .put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), Integer.MAX_VALUE)
        // Default the watermarks to absurdly low to prevent the tests
        // from failing on nodes without enough disk space
        .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "1b")
        .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "1b")
        .put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 1000)
        .put("script.stored", "true")
        .put("script.inline", "true")
        // by default we never cache below 10k docs in a segment,
        // bypass this limit so that caching gets some testing in
        // integration tests that usually create few documents
        .put(IndicesQueryCache.INDICES_QUERIES_CACHE_ALL_SEGMENTS_SETTING.getKey(), nodeOrdinal % 2 == 0)
        // wait short time for other active shards before actually deleting, default 30s not needed in tests
        .put(IndicesStore.INDICES_STORE_DELETE_SHARD_TIMEOUT.getKey(), new TimeValue(1, TimeUnit.SECONDS));
    return builder.build();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:ESIntegTestCase.java

示例3: beforeClass

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
@BeforeClass
public static void beforeClass() {
    // we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually.
    Version indexVersionCreated = randomBoolean() ? Version.CURRENT
            : VersionUtils.randomVersionBetween(random(), null, Version.CURRENT);
    nodeSettings = Settings.builder()
            .put("node.name", AbstractQueryTestCase.class.toString())
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false)
            .build();
    indexSettings = Settings.builder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated).build();

    index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");

    //create some random type with some default field, those types will stick around for all of the subclasses
    currentTypes = new String[randomIntBetween(0, 5)];
    for (int i = 0; i < currentTypes.length; i++) {
        String type = randomAsciiOfLengthBetween(1, 10);
        currentTypes[i] = type;
    }
    //set some random types to be queried as part the search request, before each test
    randomTypes = getRandomTypes();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:AbstractQueryTestCase.java

示例4: SearchService

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
public SearchService(ClusterService clusterService, IndicesService indicesService,
                     ThreadPool threadPool, ScriptService scriptService, BigArrays bigArrays, FetchPhase fetchPhase) {
    super(clusterService.getSettings());
    this.threadPool = threadPool;
    this.clusterService = clusterService;
    this.indicesService = indicesService;
    this.scriptService = scriptService;
    this.bigArrays = bigArrays;
    this.queryPhase = new QueryPhase(settings);
    this.fetchPhase = fetchPhase;

    TimeValue keepAliveInterval = KEEPALIVE_INTERVAL_SETTING.get(settings);
    this.defaultKeepAlive = DEFAULT_KEEPALIVE_SETTING.get(settings).millis();

    this.keepAliveReaper = threadPool.scheduleWithFixedDelay(new Reaper(), keepAliveInterval, Names.SAME);

    defaultSearchTimeout = DEFAULT_SEARCH_TIMEOUT_SETTING.get(settings);
    clusterService.getClusterSettings().addSettingsUpdateConsumer(DEFAULT_SEARCH_TIMEOUT_SETTING, this::setDefaultSearchTimeout);

    lowLevelCancellation = LOW_LEVEL_CANCELLATION_SETTING.get(settings);
    clusterService.getClusterSettings().addSettingsUpdateConsumer(LOW_LEVEL_CANCELLATION_SETTING, this::setLowLevelCancellation);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:23,代碼來源:SearchService.java

示例5: IngestService

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
public IngestService(Settings settings, ThreadPool threadPool,
                     Environment env, ScriptService scriptService, AnalysisRegistry analysisRegistry,
                     List<IngestPlugin> ingestPlugins) {

    final TemplateService templateService = new InternalTemplateService(scriptService);
    Processor.Parameters parameters = new Processor.Parameters(env, scriptService, templateService,
        analysisRegistry, threadPool.getThreadContext());
    Map<String, Processor.Factory> processorFactories = new HashMap<>();
    for (IngestPlugin ingestPlugin : ingestPlugins) {
        Map<String, Processor.Factory> newProcessors = ingestPlugin.getProcessors(parameters);
        for (Map.Entry<String, Processor.Factory> entry : newProcessors.entrySet()) {
            if (processorFactories.put(entry.getKey(), entry.getValue()) != null) {
                throw new IllegalArgumentException("Ingest processor [" + entry.getKey() + "] is already registered");
            }
        }
    }
    this.pipelineStore = new PipelineStore(settings, Collections.unmodifiableMap(processorFactories));
    this.pipelineExecutionService = new PipelineExecutionService(pipelineStore, threadPool);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:IngestService.java

示例6: NodeService

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
NodeService(Settings settings, ThreadPool threadPool, MonitorService monitorService, Discovery discovery,
                   TransportService transportService, IndicesService indicesService, PluginsService pluginService,
                   CircuitBreakerService circuitBreakerService, ScriptService scriptService,
                   @Nullable HttpServerTransport httpServerTransport, IngestService ingestService, ClusterService clusterService,
                   SettingsFilter settingsFilter) {
    super(settings);
    this.threadPool = threadPool;
    this.monitorService = monitorService;
    this.transportService = transportService;
    this.indicesService = indicesService;
    this.discovery = discovery;
    this.pluginService = pluginService;
    this.circuitBreakerService = circuitBreakerService;
    this.httpServerTransport = httpServerTransport;
    this.ingestService = ingestService;
    this.settingsFilter = settingsFilter;
    this.scriptService = scriptService;
    clusterService.addStateApplier(ingestService.getPipelineStore());
    clusterService.addStateApplier(ingestService.getPipelineExecutionService());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:NodeService.java

示例7: mockScriptService

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
/**
 * Mock of the script service. The script that is run looks at the
 * "_aggs" parameter visible when executing the script and simply returns the count.
 * This should be equal to the number of input InternalScriptedMetrics that are reduced
 * in total.
 */
@Override
protected ScriptService mockScriptService() {
    Settings settings = Settings.builder()
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            // no file watching, so we don't need a ResourceWatcherService
            .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "false")
            .build();
    // mock script always retuns the size of the input aggs list as result
    @SuppressWarnings("unchecked")
    MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME,
            Collections.singletonMap(REDUCE_SCRIPT_NAME, script -> {
                return ((List<Object>) script.get("_aggs")).size();
            }));
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    try {
        return new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry,
                scriptSettings);
    } catch (IOException e) {
        throw new ElasticsearchException(e);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:InternalScriptedMetricTests.java

示例8: setUp

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
@Override
public void setUp() throws Exception {
    super.setUp();
    // we have to prefer CURRENT since with the range of versions we support
    // it's rather unlikely to get the current actually.
    Settings settings = Settings.builder().put("node.name", AbstractQueryTestCase.class.toString())
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false).build();
    // create some random type with some default field, those types will
    // stick around for all of the subclasses
    currentTypes = new String[randomIntBetween(0, 5)];
    for (int i = 0; i < currentTypes.length; i++) {
        String type = randomAsciiOfLengthBetween(1, 10);
        currentTypes[i] = type;
    }
    xContentRegistry = new NamedXContentRegistry(new SearchModule(settings, false, emptyList()).getNamedXContents());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:AggregatorFactoriesTests.java

示例9: init

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
@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());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:AbstractSortTestCase.java

示例10: setUp

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
@Override
public void setUp() throws Exception {
    super.setUp();
    settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    indicesQueryCache = new IndicesQueryCache(settings);
    indexSettings = IndexSettingsModule.newIndexSettings("foo", settings);
    index = indexSettings.getIndex();
    environment = new Environment(settings);
    threadPool = new TestThreadPool("test");
    circuitBreakerService = new NoneCircuitBreakerService();
    bigArrays = new BigArrays(settings, circuitBreakerService);
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(emptyList());
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    scriptService = new ScriptService(settings, environment, new ResourceWatcherService(settings, threadPool), scriptEngineRegistry,
            scriptContextRegistry, scriptSettings);
    clusterService = ClusterServiceUtils.createClusterService(threadPool);
    nodeEnvironment = new NodeEnvironment(settings, environment);
    mapperRegistry = new IndicesModule(Collections.emptyList()).getMapperRegistry();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:IndexModuleTests.java

示例11: CrateSearchContext

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
public CrateSearchContext(long id,
                          final long nowInMillis,
                          SearchShardTarget shardTarget,
                          Engine.Searcher engineSearcher,
                          IndexService indexService,
                          final IndexShard indexShard,
                          ScriptService scriptService,
                          PageCacheRecycler pageCacheRecycler,
                          BigArrays bigArrays,
                          Counter timeEstimateCounter,
                          Optional<Scroll> scroll) {
    super(id, new CrateSearchShardRequest(nowInMillis, scroll, indexShard),
            shardTarget, engineSearcher, indexService,
            indexShard, scriptService, pageCacheRecycler,
            bigArrays, timeEstimateCounter, ParseFieldMatcher.STRICT, SearchService.NO_TIMEOUT);
    this.engineSearcher = engineSearcher;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:18,代碼來源:CrateSearchContext.java

示例12: PercolateContext

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
public PercolateContext(PercolateShardRequest request, SearchShardTarget searchShardTarget, IndexShard indexShard,
                        IndexService indexService, PageCacheRecycler pageCacheRecycler,
                        BigArrays bigArrays, ScriptService scriptService, Query aliasFilter, ParseFieldMatcher parseFieldMatcher) {
    super(parseFieldMatcher, request);
    this.indexShard = indexShard;
    this.indexService = indexService;
    this.fieldDataService = indexService.fieldData();
    this.searchShardTarget = searchShardTarget;
    this.percolateQueries = indexShard.percolateRegistry().percolateQueries();
    this.types = new String[]{request.documentType()};
    this.pageCacheRecycler = pageCacheRecycler;
    this.bigArrays = bigArrays.withCircuitBreaking();
    this.querySearchResult = new QuerySearchResult(0, searchShardTarget);
    this.engineSearcher = indexShard.acquireSearcher("percolate");
    this.searcher = new ContextIndexSearcher(engineSearcher, indexService.cache().query(), indexShard.getQueryCachingPolicy());
    this.scriptService = scriptService;
    this.numberOfShards = request.getNumberOfShards();
    this.aliasFilter = aliasFilter;
    this.startTime = request.getStartTime();
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:21,代碼來源:PercolateContext.java

示例13: ScriptedMetricAggregator

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
protected ScriptedMetricAggregator(String name, Script initScript, Script mapScript, Script combineScript, Script reduceScript,
        Map<String, Object> params, AggregationContext context, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
        throws IOException {
    super(name, context, parent, pipelineAggregators, metaData);
    this.params = params;
    ScriptService scriptService = context.searchContext().scriptService();
    if (initScript != null) {
        scriptService.executable(initScript, ScriptContext.Standard.AGGS, context.searchContext(), Collections.<String, String>emptyMap()).run();
    }
    this.mapScript = scriptService.search(context.searchContext().lookup(), mapScript, ScriptContext.Standard.AGGS, Collections.<String, String>emptyMap());
    if (combineScript != null) {
        this.combineScript = scriptService.executable(combineScript, ScriptContext.Standard.AGGS, context.searchContext(), Collections.<String, String>emptyMap());
    } else {
        this.combineScript = null;
    }
    this.reduceScript = reduceScript;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:18,代碼來源:ScriptedMetricAggregator.java

示例14: DefaultSearchContext

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
public DefaultSearchContext(long id, ShardSearchRequest request, SearchShardTarget shardTarget,
                            Engine.Searcher engineSearcher, IndexService indexService, IndexShard indexShard,
                            ScriptService scriptService, PageCacheRecycler pageCacheRecycler,
                            BigArrays bigArrays, Counter timeEstimateCounter, ParseFieldMatcher parseFieldMatcher,
                            TimeValue timeout
) {
    super(parseFieldMatcher, request);
    this.id = id;
    this.request = request;
    this.searchType = request.searchType();
    this.shardTarget = shardTarget;
    this.engineSearcher = engineSearcher;
    this.scriptService = scriptService;
    this.pageCacheRecycler = pageCacheRecycler;
    // SearchContexts use a BigArrays that can circuit break
    this.bigArrays = bigArrays.withCircuitBreaking();
    this.dfsResult = new DfsSearchResult(id, shardTarget);
    this.queryResult = new QuerySearchResult(id, shardTarget);
    this.fetchResult = new FetchSearchResult(id, shardTarget);
    this.indexShard = indexShard;
    this.indexService = indexService;
    this.searcher = new ContextIndexSearcher(engineSearcher, indexService.cache().query(), indexShard.getQueryCachingPolicy());
    this.timeEstimateCounter = timeEstimateCounter;
    this.timeoutInMillis = timeout.millis();
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:26,代碼來源:DefaultSearchContext.java

示例15: testScripting

import org.elasticsearch.script.ScriptService; //導入依賴的package包/類
public void testScripting() throws Exception {
    int randomBytesIn = randomInt();
    int randomBytesOut = randomInt();
    int randomBytesTotal = randomBytesIn + randomBytesOut;

    ScriptService scriptService = mock(ScriptService.class);
    Script script = new Script("_script");
    ExecutableScript executableScript = mock(ExecutableScript.class);
    when(scriptService.executable(any(Script.class), any())).thenReturn(executableScript);

    Map<String, Object> document = new HashMap<>();
    document.put("bytes_in", randomInt());
    document.put("bytes_out", randomInt());
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);

    doAnswer(invocationOnMock ->  {
        ingestDocument.setFieldValue("bytes_total", randomBytesTotal);
        return null;
    }).when(executableScript).run();

    ScriptProcessor processor = new ScriptProcessor(randomAsciiOfLength(10), script, scriptService);

    processor.execute(ingestDocument);

    assertThat(ingestDocument.getSourceAndMetadata(), hasKey("bytes_in"));
    assertThat(ingestDocument.getSourceAndMetadata(), hasKey("bytes_out"));
    assertThat(ingestDocument.getSourceAndMetadata(), hasKey("bytes_total"));
    assertThat(ingestDocument.getSourceAndMetadata().get("bytes_total"), is(randomBytesTotal));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:30,代碼來源:ScriptProcessorTests.java


注:本文中的org.elasticsearch.script.ScriptService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。