当前位置: 首页>>代码示例>>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;未经允许,请勿转载。