Java Code Examples for org.elasticsearch.common.settings.Settings#get()

The following examples show how to use org.elasticsearch.common.settings.Settings#get() . 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: ClusterRebalanceAllocationDecider.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void onRefreshSettings(Settings settings) {
    String newAllowRebalance = settings.get(CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE, null);
    if (newAllowRebalance != null) {
        ClusterRebalanceType newType = null;
        try {
            newType = ClusterRebalanceType.parseString(newAllowRebalance);
        } catch (IllegalArgumentException e) {
            // ignore
        }

        if (newType != null && newType != ClusterRebalanceAllocationDecider.this.type) {
            logger.info("updating [{}] from [{}] to [{}]", CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE,
                    ClusterRebalanceAllocationDecider.this.type.toString().toLowerCase(Locale.ROOT),
                    newType.toString().toLowerCase(Locale.ROOT));
            ClusterRebalanceAllocationDecider.this.type = newType;
        }
    }
}
 
Example 2
Source File: MapperTestUtils.java    From crate with Apache License 2.0 6 votes vote down vote up
public static MapperService newMapperService(NamedXContentRegistry xContentRegistry, Path tempDir, Settings settings,
                                             IndicesModule indicesModule, String indexName) throws IOException {
    Settings.Builder settingsBuilder = Settings.builder()
        .put(Environment.PATH_HOME_SETTING.getKey(), tempDir)
        .put(settings);
    if (settings.get(IndexMetaData.SETTING_VERSION_CREATED) == null) {
        settingsBuilder.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
    }
    Settings finalSettings = settingsBuilder.build();
    MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexName, finalSettings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(indexSettings, finalSettings).indexAnalyzers;
    return new MapperService(indexSettings,
        indexAnalyzers,
        xContentRegistry,
        mapperRegistry,
        () -> null);
}
 
Example 3
Source File: IndicesRequestCache.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public IndicesRequestCache(Settings settings, ClusterService clusterService, ThreadPool threadPool) {
    super(settings);
    this.clusterService = clusterService;
    this.threadPool = threadPool;
    this.cleanInterval = settings.getAsTime(INDICES_CACHE_REQUEST_CLEAN_INTERVAL, TimeValue.timeValueSeconds(60));

    String size = settings.get(INDICES_CACHE_QUERY_SIZE);
    if (size == null) {
        size = settings.get(DEPRECATED_INDICES_CACHE_QUERY_SIZE);
        if (size != null) {
            deprecationLogger.deprecated("The [" + DEPRECATED_INDICES_CACHE_QUERY_SIZE
                    + "] settings is now deprecated, use [" + INDICES_CACHE_QUERY_SIZE + "] instead");
        }
    }
    if (size == null) {
        // this cache can be very small yet still be very effective
        size = "1%";
    }
    this.size = size;

    this.expire = settings.getAsTime(INDICES_CACHE_QUERY_EXPIRE, null);
    // defaults to 4, but this is a busy map for all indices, increase it a bit by default
    this.concurrencyLevel =  settings.getAsInt(INDICES_CACHE_QUERY_CONCURRENCY_LEVEL, 16);
    if (concurrencyLevel <= 0) {
        throw new IllegalArgumentException("concurrency_level must be > 0 but was: " + concurrencyLevel);
    }
    buildCache();

    this.reaper = new Reaper();
    threadPool.schedule(cleanInterval, ThreadPool.Names.SAME, reaper);
}
 
Example 4
Source File: MorfologikTokenFilterFactory.java    From elasticsearch-analysis-morfologik with Apache License 2.0 5 votes vote down vote up
private Dictionary getDictionary(Environment env, Settings settings) throws IOException {
    String dictionaryParam = settings.get(DICTIONARY_PARAM);
    if (dictionaryParam == null) {
        return new PolishStemmer().getDictionary();
    }
    return Dictionary.read(env.configFile().resolve(dictionaryParam));
}
 
Example 5
Source File: AlterTableClusterStateExecutor.java    From crate with Apache License 2.0 5 votes vote down vote up
private Settings filterSettings(Settings settings, List<String> settingsFilter) {
    Settings.Builder settingsBuilder = Settings.builder();
    for (String settingName : settingsFilter) {
        String setting = settings.get(settingName);
        if (setting != null) {
            settingsBuilder.put(settingName, setting);
        }
    }
    return settingsBuilder.build();
}
 
Example 6
Source File: Analysis.java    From crate with Apache License 2.0 5 votes vote down vote up
public static Version parseAnalysisVersion(Settings indexSettings, Settings settings, Logger logger) {
    // check for explicit version on the specific analyzer component
    String sVersion = settings.get("version");
    if (sVersion != null) {
        return Lucene.parseVersion(sVersion, Version.LATEST, logger);
    }
    // check for explicit version on the index itself as default for all analysis components
    sVersion = indexSettings.get("index.analysis.version");
    if (sVersion != null) {
        return Lucene.parseVersion(sVersion, Version.LATEST, logger);
    }
    // resolve the analysis version based on the version the index was created with
    return org.elasticsearch.Version.indexCreated(indexSettings).luceneVersion;
}
 
Example 7
Source File: SettingMatcher.java    From crate with Apache License 2.0 5 votes vote down vote up
public static Matcher<Settings> hasEntry(String key, String value) {
    return new FeatureMatcher<>(equalTo(value), key, "hasEntry") {
        @Override
        protected String featureValueOf(Settings actual) {
            return actual.get(key);
        }
    };
}
 
Example 8
Source File: KeepWordFilterFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
KeepWordFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
    super(indexSettings, name, settings);

    final List<String> arrayKeepWords = settings.getAsList(KEEP_WORDS_KEY, null);
    final String keepWordsPath = settings.get(KEEP_WORDS_PATH_KEY, null);
    if ((arrayKeepWords == null && keepWordsPath == null) || (arrayKeepWords != null && keepWordsPath != null)) {
        // we don't allow both or none
        throw new IllegalArgumentException("keep requires either `" + KEEP_WORDS_KEY + "` or `"
                + KEEP_WORDS_PATH_KEY + "` to be configured");
    }
    if (settings.get(ENABLE_POS_INC_KEY) != null) {
        throw new IllegalArgumentException(ENABLE_POS_INC_KEY + " is not supported anymore. Please fix your analysis chain");
    }
    this.keepWords = Analysis.getWordSet(env, settings, KEEP_WORDS_KEY);
}
 
Example 9
Source File: EsUpdateSettingsTest.java    From io with Apache License 2.0 5 votes vote down vote up
private String getNumberOfReplicas(TransportClient client, String key) {
    ClusterStateRequestBuilder request = client.admin().cluster().prepareState();
    ClusterStateResponse response = request.setIndices(index.getName()).execute().actionGet();
    Settings retrievedSettings = response.getState().getMetaData().index(index.getName()).getSettings();
    String numberOfReplicas = retrievedSettings.get(key);
    return numberOfReplicas;
}
 
Example 10
Source File: Gateway.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public Gateway(Settings settings, ClusterService clusterService, NodeEnvironment nodeEnv, GatewayMetaState metaState,
               TransportNodesListGatewayMetaState listGatewayMetaState, ClusterName clusterName) {
    super(settings);
    this.clusterService = clusterService;
    this.nodeEnv = nodeEnv;
    this.metaState = metaState;
    this.listGatewayMetaState = listGatewayMetaState;
    this.clusterName = clusterName;

    clusterService.addLast(this);

    // we define what is our minimum "master" nodes, use that to allow for recovery
    this.initialMeta = settings.get("gateway.initial_meta", settings.get("gateway.local.initial_meta", settings.get("discovery.zen.minimum_master_nodes", "1")));
}
 
Example 11
Source File: FsDirectoryService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public static LockFactory buildLockFactory(Settings indexSettings) {
    String fsLock = indexSettings.get("index.store.fs.lock", indexSettings.get("index.store.fs.fs_lock", "native"));
    LockFactory lockFactory;
    if (fsLock.equals("native")) {
        lockFactory = NativeFSLockFactory.INSTANCE;
    } else if (fsLock.equals("simple")) {
        lockFactory = SimpleFSLockFactory.INSTANCE;
    } else {
        throw new IllegalArgumentException("unrecognized fs_lock \"" + fsLock + "\": must be native or simple");
    }
    return lockFactory;
}
 
Example 12
Source File: SrvUnicastHostsProvider.java    From elasticsearch-srv-discovery with MIT License 5 votes vote down vote up
@Inject
public SrvUnicastHostsProvider(Settings settings, TransportService transportService, Version version) {
    super(settings);
    this.transportService = transportService;
    this.version = version;

    this.query = settings.get(DISCOVERY_SRV_QUERY);
    logger.debug("Using query {}", this.query);
    this.resolver = buildResolver(settings);
}
 
Example 13
Source File: SamlHTTPMetadataResolver.java    From deprecated-security-advanced-modules with Apache License 2.0 5 votes vote down vote up
SamlHTTPMetadataResolver(Settings esSettings, Path configPath) throws Exception {
    super(createHttpClient(esSettings, configPath), esSettings.get("idp.metadata_url"));
    setId(HTTPSamlAuthenticator.class.getName() + "_" + (++componentIdCounter));
    setRequireValidMetadata(true);
    setFailFastInitialization(false);
    setMinRefreshDelay(esSettings.getAsLong("idp.min_refresh_delay", 60L * 1000L));
    setMaxRefreshDelay(esSettings.getAsLong("idp.max_refresh_delay", 14400000L));
    setRefreshDelayFactor(esSettings.getAsFloat("idp.refresh_delay_factor", 0.75f));
    BasicParserPool basicParserPool = new BasicParserPool();
    basicParserPool.initialize();
    setParserPool(basicParserPool);
}
 
Example 14
Source File: CreateTenantStatementAnalyzer.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public CreateTenantAnalyzedStatement visitCreateTenant(CreateTenant node, Analysis context) {
    // Add SQL Authentication
    UserProperty currentOperateUser = context.parameterContext().userProperty();
    if (!currentOperateUser.getUsernameWithoutTenant().equalsIgnoreCase(UserProperty.ROOT_NAME)) {
        throw new NoPermissionException(RestStatus.FORBIDDEN.getStatus(), "only root have permission to create tenant");
    }
    Settings settings = GenericPropertiesConverter.settingsFromProperties(
            node.properties(), context.parameterContext(), SETTINGS).build();
    CreateTenantAnalyzedStatement statement = new CreateTenantAnalyzedStatement(node.name(), 
            settings.get(TenantSettings.SUPERUSER_PASSWORD.name()), 
            settings.getAsInt(TenantSettings.NUMBER_OF_INSTANCES.name(), TenantSettings.NUMBER_OF_INSTANCES.defaultValue()), 
            settings.get(TenantSettings.INSTANCE_LIST.name()));
    return statement;   
}
 
Example 15
Source File: PatternReplaceCharFilterFactory.java    From crate with Apache License 2.0 5 votes vote down vote up
PatternReplaceCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
    super(indexSettings, name);

    String sPattern = settings.get("pattern");
    if (!Strings.hasLength(sPattern)) {
        throw new IllegalArgumentException("pattern is missing for [" + name + "] char filter of type 'pattern_replace'");
    }
    pattern = Regex.compile(sPattern, settings.get("flags"));
    replacement = settings.get("replacement", ""); // when not set or set to "", use "".
}
 
Example 16
Source File: IcuFoldingTokenFilterFactory.java    From elasticsearch-plugin-bundle with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected String getNormalizationName(Settings settings) {
    return settings.get("normalization_name", "utr30");
}
 
Example 17
Source File: PrimaryShardAllocator.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public PrimaryShardAllocator(Settings settings) {
    super(settings);
    this.initialShards = settings.get("gateway.initial_shards", settings.get("gateway.local.initial_shards", "quorum"));
    logger.debug("using initial_shards [{}]", initialShards);
}
 
Example 18
Source File: Saml2SettingsProvider.java    From deprecated-security-advanced-modules with Apache License 2.0 4 votes vote down vote up
Saml2SettingsProvider(Settings esSettings, MetadataResolver metadataResolver) {
    this.esSettings = esSettings;
    this.metadataResolver = metadataResolver;
    this.idpEntityId = esSettings.get("idp.entity_id");
}
 
Example 19
Source File: SynonymTokenFilterFactory.java    From elasticsearch-analysis-synonym with Apache License 2.0 4 votes vote down vote up
public SynonymTokenFilterFactory(final IndexSettings indexSettings, final Environment environment, final String name, final Settings settings,
        final AnalysisRegistry analysisRegistry) throws IOException {
    super(indexSettings, name, settings);

    this.ignoreCase = settings.getAsBoolean("ignore_case", false);
    final boolean expand = settings.getAsBoolean("expand", true);

    final String tokenizerName = settings.get("tokenizer", "whitespace");

    AnalysisModule.AnalysisProvider<TokenizerFactory> tokenizerFactoryFactory = null;
    if (analysisRegistry != null) {
        tokenizerFactoryFactory = analysisRegistry.getTokenizerProvider(tokenizerName, indexSettings);
        if (tokenizerFactoryFactory == null) {
            throw new IllegalArgumentException("failed to find tokenizer [" + tokenizerName + "] for synonym token filter");
        }
    }

    final TokenizerFactory tokenizerFactory = tokenizerFactoryFactory == null ? null
            : tokenizerFactoryFactory.get(indexSettings, environment, tokenizerName, AnalysisRegistry
                    .getSettingsFromIndexSettings(indexSettings, AnalysisRegistry.INDEX_ANALYSIS_TOKENIZER + "." + tokenizerName));

    final Analyzer analyzer = new Analyzer() {
        @Override
        protected TokenStreamComponents createComponents(final String fieldName) {
            final Tokenizer tokenizer = tokenizerFactory == null ? new WhitespaceTokenizer() : tokenizerFactory.create();
            final TokenStream stream = ignoreCase ? new LowerCaseFilter(tokenizer) : tokenizer;
            return new TokenStreamComponents(tokenizer, stream);
        }
    };

    synonymLoader = new SynonymLoader(environment, settings, expand, analyzer);
    if (synonymLoader.getSynonymMap() == null) {
        if (settings.getAsList("synonyms", null) != null) {
            logger.warn("synonyms values are empty.");
        } else if (settings.get("synonyms_path") != null) {
            logger.warn("synonyms_path[{}] is empty.", settings.get("synonyms_path"));
        } else {
            throw new IllegalArgumentException("synonym requires either `synonyms` or `synonyms_path` to be configured");
        }
    }
}
 
Example 20
Source File: NodeEnvironment.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * @param indexSettings settings for an index
 * @return true if the index has a custom data path
 */
public static boolean hasCustomDataPath(Settings indexSettings) {
    return indexSettings.get(IndexMetaData.SETTING_DATA_PATH) != null;
}