Search in sources :

Example 6 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class IndexSettingsModule method newIndexSettings.

public static IndexSettings newIndexSettings(Index index, Settings indexSetting, Settings nodeSettings, Setting<?>... setting) {
    Settings build = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(indexSetting).build();
    IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).build();
    Set<Setting<?>> settingSet = new HashSet<>(IndexScopedSettings.BUILT_IN_INDEX_SETTINGS);
    if (setting.length > 0) {
        settingSet.addAll(Arrays.asList(setting));
    }
    return new IndexSettings(metaData, nodeSettings, new IndexScopedSettings(Settings.EMPTY, settingSet));
}
Also used : IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) Setting(org.elasticsearch.common.settings.Setting) IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexScopedSettings(org.elasticsearch.common.settings.IndexScopedSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) HashSet(java.util.HashSet)

Example 7 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class IndexFolderUpgraderTests method testUpgradeCustomDataPath.

/**
     * tests custom data paths are upgraded
     */
public void testUpgradeCustomDataPath() throws IOException {
    Path customPath = createTempDir();
    final Settings nodeSettings = Settings.builder().put(NodeEnvironment.ADD_NODE_LOCK_ID_TO_CUSTOM_PATH.getKey(), randomBoolean()).put(Environment.PATH_SHARED_DATA_SETTING.getKey(), customPath.toAbsolutePath().toString()).build();
    try (NodeEnvironment nodeEnv = newNodeEnvironment(nodeSettings)) {
        final Index index = new Index(randomAsciiOfLength(10), UUIDs.randomBase64UUID());
        Settings settings = Settings.builder().put(nodeSettings).put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0).put(IndexMetaData.SETTING_DATA_PATH, customPath.toAbsolutePath().toString()).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 5)).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).build();
        IndexMetaData indexState = IndexMetaData.builder(index.getName()).settings(settings).build();
        int numIdxFiles = randomIntBetween(1, 5);
        int numTranslogFiles = randomIntBetween(1, 5);
        IndexSettings indexSettings = new IndexSettings(indexState, nodeSettings);
        writeIndex(nodeEnv, indexSettings, numIdxFiles, numTranslogFiles);
        IndexFolderUpgrader helper = new IndexFolderUpgrader(settings, nodeEnv);
        helper.upgrade(indexSettings.getIndex().getName());
        checkIndex(nodeEnv, indexSettings, numIdxFiles, numTranslogFiles);
    }
}
Also used : Path(java.nio.file.Path) ShardPath(org.elasticsearch.index.shard.ShardPath) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndexSettings(org.elasticsearch.index.IndexSettings) Index(org.elasticsearch.index.Index) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 8 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class NodeEnvironmentTests method testCustomDataPaths.

public void testCustomDataPaths() throws Exception {
    String[] dataPaths = tmpPaths();
    NodeEnvironment env = newNodeEnvironment(dataPaths, "/tmp", Settings.EMPTY);
    final Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_INDEX_UUID, "myindexUUID").build();
    IndexSettings s1 = IndexSettingsModule.newIndexSettings("myindex", indexSettings);
    IndexSettings s2 = IndexSettingsModule.newIndexSettings("myindex", Settings.builder().put(indexSettings).put(IndexMetaData.SETTING_DATA_PATH, "/tmp/foo").build());
    Index index = new Index("myindex", "myindexUUID");
    ShardId sid = new ShardId(index, 0);
    assertFalse("no settings should mean no custom data path", s1.hasCustomDataPath());
    assertTrue("settings with path_data should have a custom data path", s2.hasCustomDataPath());
    assertThat(env.availableShardPaths(sid), equalTo(env.availableShardPaths(sid)));
    assertThat(env.resolveCustomLocation(s2, sid), equalTo(PathUtils.get("/tmp/foo/0/" + index.getUUID() + "/0")));
    assertThat("shard paths with a custom data_path should contain only regular paths", env.availableShardPaths(sid), equalTo(stringsToPaths(dataPaths, "nodes/0/indices/" + index.getUUID() + "/0")));
    assertThat("index paths uses the regular template", env.indexPaths(index), equalTo(stringsToPaths(dataPaths, "nodes/0/indices/" + index.getUUID())));
    IndexSettings s3 = new IndexSettings(s2.getIndexMetaData(), Settings.builder().put(NodeEnvironment.ADD_NODE_LOCK_ID_TO_CUSTOM_PATH.getKey(), false).build());
    assertThat(env.availableShardPaths(sid), equalTo(env.availableShardPaths(sid)));
    assertThat(env.resolveCustomLocation(s3, sid), equalTo(PathUtils.get("/tmp/foo/" + index.getUUID() + "/0")));
    assertThat("shard paths with a custom data_path should contain only regular paths", env.availableShardPaths(sid), equalTo(stringsToPaths(dataPaths, "nodes/0/indices/" + index.getUUID() + "/0")));
    assertThat("index paths uses the regular template", env.indexPaths(index), equalTo(stringsToPaths(dataPaths, "nodes/0/indices/" + index.getUUID())));
    env.close();
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexSettings(org.elasticsearch.index.IndexSettings) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 9 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class SynonymsAnalysisTests method testSynonymsAnalysis.

public void testSynonymsAnalysis() throws IOException {
    InputStream synonyms = getClass().getResourceAsStream("synonyms.txt");
    InputStream synonymsWordnet = getClass().getResourceAsStream("synonyms_wordnet.txt");
    Path home = createTempDir();
    Path config = home.resolve("config");
    Files.createDirectory(config);
    Files.copy(synonyms, config.resolve("synonyms.txt"));
    Files.copy(synonymsWordnet, config.resolve("synonyms_wordnet.txt"));
    String json = "/org/elasticsearch/index/analysis/synonyms/synonyms.json";
    Settings settings = Settings.builder().loadFromStream(json, getClass().getResourceAsStream(json)).put(Environment.PATH_HOME_SETTING.getKey(), home).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    indexAnalyzers = createTestAnalysis(idxSettings, settings).indexAnalyzers;
    match("synonymAnalyzer", "kimchy is the dude abides", "shay is the elasticsearch man!");
    match("synonymAnalyzer_file", "kimchy is the dude abides", "shay is the elasticsearch man!");
    match("synonymAnalyzerWordnet", "abstain", "abstain refrain desist");
    match("synonymAnalyzerWordnet_file", "abstain", "abstain refrain desist");
    match("synonymAnalyzerWithsettings", "kimchy", "sha hay");
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 10 with IndexSettings

use of org.elasticsearch.index.IndexSettings in project elasticsearch by elastic.

the class CodecTests method createCodecService.

private CodecService createCodecService() throws IOException {
    Settings nodeSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
    IndexSettings settings = IndexSettingsModule.newIndexSettings("_na", nodeSettings);
    SimilarityService similarityService = new SimilarityService(settings, Collections.emptyMap());
    IndexAnalyzers indexAnalyzers = createTestAnalysis(settings, nodeSettings).indexAnalyzers;
    MapperRegistry mapperRegistry = new MapperRegistry(Collections.emptyMap(), Collections.emptyMap());
    MapperService service = new MapperService(settings, indexAnalyzers, xContentRegistry(), similarityService, mapperRegistry, () -> null);
    return new CodecService(service, ESLoggerFactory.getLogger("test"));
}
Also used : MapperRegistry(org.elasticsearch.indices.mapper.MapperRegistry) IndexSettings(org.elasticsearch.index.IndexSettings) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) MapperService(org.elasticsearch.index.mapper.MapperService)

Aggregations

IndexSettings (org.elasticsearch.index.IndexSettings)83 Settings (org.elasticsearch.common.settings.Settings)53 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)28 Index (org.elasticsearch.index.Index)25 ShardId (org.elasticsearch.index.shard.ShardId)13 Environment (org.elasticsearch.env.Environment)12 IOException (java.io.IOException)11 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)11 Path (java.nio.file.Path)9 ShardPath (org.elasticsearch.index.shard.ShardPath)9 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 Directory (org.apache.lucene.store.Directory)8 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)7 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 HashMap (java.util.HashMap)5 Version (org.elasticsearch.Version)5 IndexService (org.elasticsearch.index.IndexService)5 Store (org.elasticsearch.index.store.Store)5 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4