org.elasticsearch.script.ScriptService Java Examples

The following examples show how to use org.elasticsearch.script.ScriptService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexQueryParserService.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Inject
public IndexQueryParserService(Index index, IndexSettingsService indexSettingsService,
                               IndicesQueriesRegistry indicesQueriesRegistry,
                               ScriptService scriptService, AnalysisService analysisService,
                               MapperService mapperService, IndexCache indexCache, IndexFieldDataService fieldDataService,
                               BitsetFilterCache bitsetFilterCache,
                               @Nullable SimilarityService similarityService) {
    super(index, indexSettingsService.getSettings());
    this.indexSettingsService = indexSettingsService;
    this.scriptService = scriptService;
    this.analysisService = analysisService;
    this.mapperService = mapperService;
    this.similarityService = similarityService;
    this.indexCache = indexCache;
    this.fieldDataService = fieldDataService;
    this.bitsetFilterCache = bitsetFilterCache;

    Settings indexSettings = indexSettingsService.getSettings();
    this.defaultField = indexSettings.get(DEFAULT_FIELD, AllFieldMapper.NAME);
    this.queryStringLenient = indexSettings.getAsBoolean(QUERY_STRING_LENIENT, false);
    this.parseFieldMatcher = new ParseFieldMatcher(indexSettings);
    this.defaultAllowUnmappedFields = indexSettings.getAsBoolean(ALLOW_UNMAPPED, true);
    this.indicesQueriesRegistry = indicesQueriesRegistry;
}
 
Example #2
Source File: TransportTermsByQueryAction.java    From siren-join with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 */
@Inject
public TransportTermsByQueryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
                                   TransportService transportService, IndicesService indicesService,
                                   CircuitBreakerService breakerService,
                                   ScriptService scriptService, PageCacheRecycler pageCacheRecycler,
                                   BigArrays bigArrays, ActionFilters actionFilters,
                                   IndexNameExpressionResolver indexNameExpressionResolver, Client client) {
  super(settings, TermsByQueryAction.NAME, threadPool, clusterService, transportService, actionFilters,
          indexNameExpressionResolver, TermsByQueryRequest.class, TermsByQueryShardRequest.class,
          // Use the generic threadpool which is cached, as we can end up with deadlock with the SEARCH threadpool
          ThreadPool.Names.GENERIC);
  this.indicesService = indicesService;
  this.scriptService = scriptService;
  this.pageCacheRecycler = pageCacheRecycler;
  this.bigArrays = bigArrays;
  this.breakerService = breakerService;
  this.client = client;
}
 
Example #3
Source File: DefaultSearchContext.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #4
Source File: LtrQueryParserPlugin.java    From elasticsearch-learning-to-rank with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<Object> createComponents(Client client,
                                           ClusterService clusterService,
                                           ThreadPool threadPool,
                                           ResourceWatcherService resourceWatcherService,
                                           ScriptService scriptService,
                                           NamedXContentRegistry xContentRegistry,
                                           Environment environment,
                                           NodeEnvironment nodeEnvironment,
                                           NamedWriteableRegistry namedWriteableRegistry,
                                           IndexNameExpressionResolver indexNameExpressionResolver) {
    clusterService.addListener(event -> {
        for (Index i : event.indicesDeleted()) {
            if (IndexFeatureStore.isIndexStore(i.getName())) {
                caches.evict(i.getName());
            }
        }
    });
    return asList(caches, parserFactory);
}
 
Example #5
Source File: NodeTestConfig.java    From elastic-crud with Apache License 2.0 6 votes vote down vote up
@Bean(destroyMethod="close")
Node newNode() throws NodeValidationException {
  final Path tempDir = createTempDir().toPath();
  final Settings settings = Settings.builder()
    .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), new ClusterName("single-node-cluster" + System.nanoTime()))
    .put(Environment.PATH_HOME_SETTING.getKey(), tempDir)
    .put(Environment.PATH_REPO_SETTING.getKey(), tempDir.resolve("repo"))
    .put(Environment.PATH_SHARED_DATA_SETTING.getKey(), createTempDir().getParent())
    .put("node.name", "single-node")
    .put("script.inline", "true")
    .put("script.stored", "true")
    .put(ScriptService.SCRIPT_MAX_COMPILATIONS_PER_MINUTE.getKey(), 1000)
    .put(EsExecutors.PROCESSORS_SETTING.getKey(), 1)
    .put(NetworkModule.HTTP_ENABLED.getKey(), false)
    .put("discovery.type", "zen")
    .put("transport.type", "local")
    .put(Node.NODE_DATA_SETTING.getKey(), true)
    .put(NODE_ID_SEED_SETTING.getKey(), System.nanoTime())
    .build();
  return new Node(settings).start(); // NOSONAR
}
 
Example #6
Source File: DynamicRanker.java    From elasticsearch-dynarank with Apache License 2.0 6 votes vote down vote up
@Inject
public DynamicRanker(final Settings settings, final Client client, final ClusterService clusterService,
        final ScriptService scriptService, final ThreadPool threadPool, final ActionFilters filters,
        final NamedWriteableRegistry namedWriteableRegistry) {
    this.client = client;
    this.clusterService = clusterService;
    this.scriptService = scriptService;
    this.threadPool = threadPool;
    this.namedWriteableRegistry = namedWriteableRegistry;

    logger.info("Initializing DynamicRanker");

    final TimeValue expire = SETTING_DYNARANK_CACHE_EXPIRE.get(settings);
    cleanInterval = SETTING_DYNARANK_CACHE_CLEAN_INTERVAL.get(settings);

    final CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().concurrencyLevel(16);
    if (expire.millis() >= 0) {
        builder.expireAfterAccess(expire.millis(), TimeUnit.MILLISECONDS);
    }
    scriptInfoCache = builder.build();
}
 
Example #7
Source File: ScriptedMetricAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: AbstractTransportExportAction.java    From elasticsearch-inout-plugin with Apache License 2.0 6 votes vote down vote up
public AbstractTransportExportAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
                                     TransportService transportService, IndicesService indicesService,
                                     ScriptService scriptService, CacheRecycler cacheRecycler,
                                     IExportParser exportParser, Exporter exporter,
                                     NodeEnvironment nodeEnv) {
    super(settings, threadPool, clusterService, transportService);
    this.indicesService = indicesService;
    this.scriptService = scriptService;
    this.cacheRecycler = cacheRecycler;
    this.exportParser = exportParser;
    this.exporter = exporter;
    File[] paths = nodeEnv.nodeDataLocations();
    if (paths.length > 0) {
        nodePath = paths[0].getAbsolutePath();
    }
}
 
Example #9
Source File: PercolateContext.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #10
Source File: CrateSearchContext.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: TransportReindexAction.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportReindexAction(Settings settings, ThreadPool threadPool,
        ClusterService clusterService, TransportService transportService, CacheRecycler cacheRecycler,
        IndicesService indicesService, ScriptService scriptService,
        ReindexParser parser, Writer writer) {
    super(settings, threadPool, clusterService, transportService, cacheRecycler, indicesService,
            scriptService, parser, writer);
}
 
Example #12
Source File: TransportSearchIntoAction.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportSearchIntoAction(Settings settings,
        ThreadPool threadPool, ClusterService clusterService,
        TransportService transportService, CacheRecycler cacheRecycler,
        IndicesService indicesService, ScriptService scriptService,
        SearchIntoParser parser, Writer writer) {
    super(settings, threadPool, clusterService, transportService, cacheRecycler, indicesService,
        scriptService, parser, writer);
}
 
Example #13
Source File: AbstractTransportSearchIntoAction.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Inject
public AbstractTransportSearchIntoAction(Settings settings,
        ThreadPool threadPool, ClusterService clusterService,
        TransportService transportService, CacheRecycler cacheRecycler,
        IndicesService indicesService, ScriptService scriptService,
        ISearchIntoParser parser, Writer writer) {
    super(settings, threadPool, clusterService, transportService);
    this.indicesService = indicesService;
    this.cacheRecycler = cacheRecycler;
    this.scriptService = scriptService;
    this.parser = parser;
    this.writer = writer;
}
 
Example #14
Source File: TransportExistsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportExistsAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService,
                            IndicesService indicesService, ScriptService scriptService,
                            PageCacheRecycler pageCacheRecycler, BigArrays bigArrays, ActionFilters actionFilters,
                             IndexNameExpressionResolver indexNameExpressionResolver) {
    super(settings, ExistsAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
            ExistsRequest.class, ShardExistsRequest.class, ThreadPool.Names.SEARCH);
    this.indicesService = indicesService;
    this.scriptService = scriptService;
    this.pageCacheRecycler = pageCacheRecycler;
    this.bigArrays = bigArrays;
}
 
Example #15
Source File: SearchIntoContext.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
public SearchIntoContext(long id, ShardSearchRequest request,
        SearchShardTarget shardTarget, Engine.Searcher engineSearcher,
        IndexService indexService, IndexShard indexShard,
        ScriptService scriptService, CacheRecycler cacheRecycler) {
    super(id, request, shardTarget, engineSearcher, indexService,
            indexShard, scriptService, cacheRecycler);
}
 
Example #16
Source File: TransportExportAction.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportExportAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
                             TransportService transportService, IndicesService indicesService,
                             ScriptService scriptService, CacheRecycler cacheRecycler,
                             ExportParser exportParser, Exporter exporter, NodeEnvironment nodeEnv) {
    super(settings, threadPool, clusterService, transportService, indicesService, scriptService,
        cacheRecycler, exportParser, exporter, nodeEnv);
}
 
Example #17
Source File: ElasticSearchDefaultIndexStrategy.java    From camunda-bpm-elasticsearch with Apache License 2.0 5 votes vote down vote up
protected UpdateRequestBuilder prepareOtherHistoricEventsUpdateRequest(HistoryEvent historyEvent, UpdateRequestBuilder updateRequestBuilder) throws IOException {
  HashMap<String, Object> scriptParams = new HashMap<String, Object>();

  if (historyEvent instanceof HistoricActivityInstanceEventEntity) {
    scriptParams.put("isActivityInstanceEvent", true);
    scriptParams.put("isTaskInstanceEvent", false);
    scriptParams.put("isVariableUpdateEvent", false);
  } else if (historyEvent instanceof HistoricTaskInstanceEventEntity) {
    scriptParams.put("isActivityInstanceEvent", false);
    scriptParams.put("isTaskInstanceEvent", true);
    scriptParams.put("isVariableUpdateEvent", false);
  } else {
    scriptParams.put("isActivityInstanceEvent", false);
    scriptParams.put("isTaskInstanceEvent", false);
    scriptParams.put("isVariableUpdateEvent", true);
  }

  String eventJson = transformer.transformToJson(historyEvent);
  // needed otherwise the resulting json is not an array/list and the update script throws an error
  List<Map<String,Object>> events = transformer.transformJsonToList("[" + eventJson + "]");
  scriptParams.put("value", events);

  updateRequestBuilder.setScript(ES_INDEX_UPDATE_SCRIPT, ScriptService.ScriptType.INLINE)
      .setScriptParams(scriptParams);

  return updateRequestBuilder;
}
 
Example #18
Source File: TransportDumpAction.java    From elasticsearch-inout-plugin with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportDumpAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
                           TransportService transportService, IndicesService indicesService,
                           ScriptService scriptService, CacheRecycler cacheRecycler,
                           DumpParser dumpParser, Exporter exporter, NodeEnvironment nodeEnv) {
    super(settings, threadPool, clusterService, transportService, indicesService, scriptService,
        cacheRecycler, dumpParser, exporter, nodeEnv);
}
 
Example #19
Source File: TestTransportClient.java    From jframe with Apache License 2.0 5 votes vote down vote up
public void testUpdate() throws Exception {
    UpdateRequest updateRequest = new UpdateRequest();
    updateRequest.index("index");
    updateRequest.type("type");
    updateRequest.id("1");
    updateRequest.doc(XContentFactory.jsonBuilder().startObject().field("gender", "male").endObject());
    UpdateResponse response = client.update(updateRequest).get();
    System.out.println(response.toString());

    client.prepareUpdate("ttl", "doc", "1").setScript(new Script("ctx._source.gender = \"male\"", ScriptService.ScriptType.INLINE, null, null))
            .get();

    client.prepareUpdate("ttl", "doc", "1").setDoc(XContentFactory.jsonBuilder().startObject().field("gender", "male").endObject()).get();
}
 
Example #20
Source File: RangerElasticsearchPlugin.java    From ranger with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Object> createComponents(final Client client, final ClusterService clusterService,
		final ThreadPool threadPool, final ResourceWatcherService resourceWatcherService,
		final ScriptService scriptService, final NamedXContentRegistry xContentRegistry,
		final Environment environment, final NodeEnvironment nodeEnvironment,
		final NamedWriteableRegistry namedWriteableRegistry) {

	addPluginConfig2Classpath(environment);

	rangerSecurityActionFilter = new RangerSecurityActionFilter(threadPool.getThreadContext());
	return Collections.singletonList(rangerSecurityActionFilter);
}
 
Example #21
Source File: DynamicSynonymPlugin.java    From elasticsearch-analysis-dynamic-synonym with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Object> createComponents(Client client,
                                           ClusterService clusterService,
                                           ThreadPool threadPool,
                                           ResourceWatcherService resourceWatcherService,
                                           ScriptService scriptService,
                                           NamedXContentRegistry xContentRegistry) {
    Collection<Object> components = new ArrayList<>();
    components.add(pluginComponent);
    return components;
}
 
Example #22
Source File: PutIndexedScriptResponse.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void readFrom(StreamInput in) throws IOException {
    super.readFrom(in);
    index = ScriptService.SCRIPT_INDEX;
    scriptLang = in.readString();
    id = in.readString();
    version = in.readLong();
    created = in.readBoolean();
}
 
Example #23
Source File: PutIndexedScriptResponse.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public PutIndexedScriptResponse(String type, String id, long version, boolean created) {
    this.index = ScriptService.SCRIPT_INDEX;
    this.id = id;
    this.scriptLang = type;
    this.version = version;
    this.created = created;
}
 
Example #24
Source File: PutIndexedScriptRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    String sSource = "_na_";
    try {
        sSource = XContentHelper.convertToJson(source, false);
    } catch (Exception e) {
        // ignore
    }
    return "index {[" + ScriptService.SCRIPT_INDEX + "][" + scriptLang + "][" + id + "], source[" + sSource + "]}";
}
 
Example #25
Source File: TransportPutIndexedScriptAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportPutIndexedScriptAction(Settings settings, ThreadPool threadPool, ScriptService scriptService,
                                       TransportService transportService, ActionFilters actionFilters,
                                       IndexNameExpressionResolver indexNameExpressionResolver) {
    super(settings, PutIndexedScriptAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, PutIndexedScriptRequest.class);
    this.scriptService = scriptService;
}
 
Example #26
Source File: TransportExplainAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportExplainAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
                              TransportService transportService, IndicesService indicesService,
                              ScriptService scriptService, PageCacheRecycler pageCacheRecycler,
                              BigArrays bigArrays, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
    super(settings, ExplainAction.NAME, threadPool, clusterService, transportService, actionFilters, indexNameExpressionResolver,
            ExplainRequest.class, ThreadPool.Names.GET);
    this.indicesService = indicesService;
    this.scriptService = scriptService;
    this.pageCacheRecycler = pageCacheRecycler;
    this.bigArrays = bigArrays;
}
 
Example #27
Source File: TransportValidateQueryAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public TransportValidateQueryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService,
                                    TransportService transportService, IndicesService indicesService,
                                    ScriptService scriptService, PageCacheRecycler pageCacheRecycler,
                                    BigArrays bigArrays, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
    super(settings, ValidateQueryAction.NAME, threadPool, clusterService, transportService, actionFilters,
            indexNameExpressionResolver, ValidateQueryRequest.class, ShardValidateQueryRequest.class, ThreadPool.Names.SEARCH);
    this.indicesService = indicesService;
    this.scriptService = scriptService;
    this.pageCacheRecycler = pageCacheRecycler;
    this.bigArrays = bigArrays;
}
 
Example #28
Source File: OpenDistroSecuritySSLPlugin.java    From deprecated-security-ssl with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Object> createComponents(Client localClient, ClusterService clusterService, ThreadPool threadPool,
        ResourceWatcherService resourceWatcherService, ScriptService scriptService, NamedXContentRegistry xContentRegistry,
        Environment environment, NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) {

    final List<Object> components = new ArrayList<>(1);
    
    if(client) {
        return components;
    }
    
    final String principalExtractorClass = settings.get(SSLConfigConstants.OPENDISTRO_SECURITY_SSL_TRANSPORT_PRINCIPAL_EXTRACTOR_CLASS, null);

    if(principalExtractorClass == null) {
        principalExtractor = new com.amazon.opendistroforelasticsearch.security.ssl.transport.DefaultPrincipalExtractor();
    } else {
        try {
            log.debug("Try to load and instantiate '{}'", principalExtractorClass);
            Class<?> principalExtractorClazz = Class.forName(principalExtractorClass);
            principalExtractor = (PrincipalExtractor) principalExtractorClazz.newInstance();
        } catch (Exception e) {
            log.error("Unable to load '{}' due to", principalExtractorClass, e);
            throw new ElasticsearchException(e);
        }
    }
    
    components.add(principalExtractor);
    
    return components;
}
 
Example #29
Source File: MetaDataIndexUpgradeService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public MetaDataIndexUpgradeService(Settings settings, ScriptService scriptService, MapperRegistry mapperRegistry,
                                   DynamicArrayFieldMapperBuilderFactoryProvider dynamicArrayFieldMapperBuilderFactoryProvider) {
    super(settings);
    this.scriptService = scriptService;
    this.mapperRegistry = mapperRegistry;
    this.dynamicArrayFieldMapperBuilderFactoryProvider = dynamicArrayFieldMapperBuilderFactoryProvider;
    final String pre20HashFunctionName = settings.get(DEPRECATED_SETTING_ROUTING_HASH_FUNCTION, null);
    final boolean hasCustomPre20HashFunction = pre20HashFunctionName != null;
    // the hash function package has changed we replace the two hash functions if their fully qualified name is used.
    if (hasCustomPre20HashFunction) {
        switch (pre20HashFunctionName) {
            case "Simple":
            case "simple":
            case "org.elasticsearch.cluster.routing.operation.hash.simple.SimpleHashFunction":
                pre20HashFunction = SimpleHashFunction.class;
                break;
            case "Djb":
            case "djb":
            case "org.elasticsearch.cluster.routing.operation.hash.djb.DjbHashFunction":
                pre20HashFunction = DjbHashFunction.class;
                break;
            default:
                try {
                    pre20HashFunction = Class.forName(pre20HashFunctionName).asSubclass(HashFunction.class);
                } catch (ClassNotFoundException|NoClassDefFoundError e) {
                    throw new ElasticsearchException("failed to load custom hash function [" + pre20HashFunctionName + "]", e);
                }
        }
    } else {
        pre20HashFunction = DjbHashFunction.class;
    }
    pre20UseType = settings.getAsBoolean(DEPRECATED_SETTING_ROUTING_USE_TYPE, null);
    if (hasCustomPre20HashFunction || pre20UseType != null) {
        logger.warn("Settings [{}] and [{}] are deprecated. Index settings from your old indices have been updated to record the fact that they "
                + "used some custom routing logic, you can now remove these settings from your `elasticsearch.yml` file", DEPRECATED_SETTING_ROUTING_HASH_FUNCTION, DEPRECATED_SETTING_ROUTING_USE_TYPE);
    }
}
 
Example #30
Source File: DocumentMapper.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link #transform(ScriptService, Script)} instead.
 */
@Deprecated
public Builder transform(ScriptService scriptService, String script, ScriptType scriptType, String language,
        Map<String, Object> parameters) {
    sourceTransforms.add(new ScriptTransform(scriptService, new Script(script, scriptType, language, parameters)));
    return this;
}