Search in sources :

Example 31 with IndexSettings

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

the class SimilarityServiceTests method testOverrideBuiltInSimilarityPreV3.

// Pre v3 indices could override built-in similarities
public void testOverrideBuiltInSimilarityPreV3() {
    Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_0_0).put("index.similarity.BM25.type", "classic").build();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", settings);
    SimilarityService service = new SimilarityService(indexSettings, Collections.emptyMap());
    assertTrue(service.getSimilarity("BM25") instanceof ClassicSimilarityProvider);
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 32 with IndexSettings

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

the class StoreTests method testRefCount.

public void testRefCount() throws IOException {
    final ShardId shardId = new ShardId("index", "_na_", 1);
    DirectoryService directoryService = new LuceneManagedDirectoryService(random());
    IndexSettings indexSettings = INDEX_SETTINGS;
    Store store = new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId));
    int incs = randomIntBetween(1, 100);
    for (int i = 0; i < incs; i++) {
        if (randomBoolean()) {
            store.incRef();
        } else {
            assertTrue(store.tryIncRef());
        }
        store.ensureOpen();
    }
    for (int i = 0; i < incs; i++) {
        store.decRef();
        store.ensureOpen();
    }
    store.incRef();
    store.close();
    for (int i = 0; i < incs; i++) {
        if (randomBoolean()) {
            store.incRef();
        } else {
            assertTrue(store.tryIncRef());
        }
        store.ensureOpen();
    }
    for (int i = 0; i < incs; i++) {
        store.decRef();
        store.ensureOpen();
    }
    store.decRef();
    assertThat(store.refCount(), Matchers.equalTo(0));
    assertFalse(store.tryIncRef());
    try {
        store.incRef();
        fail(" expected exception");
    } catch (AlreadyClosedException ex) {
    }
    try {
        store.ensureOpen();
        fail(" expected exception");
    } catch (AlreadyClosedException ex) {
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexSettings(org.elasticsearch.index.IndexSettings) DummyShardLock(org.elasticsearch.test.DummyShardLock) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException)

Example 33 with IndexSettings

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

the class IndicesServiceTests method testCanDeleteShardContent.

public void testCanDeleteShardContent() {
    IndicesService indicesService = getIndicesService();
    IndexMetaData meta = IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1).build();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", meta.getSettings());
    ShardId shardId = new ShardId(meta.getIndex(), 0);
    assertEquals("no shard location", indicesService.canDeleteShardContent(shardId, indexSettings), ShardDeletionCheckResult.NO_FOLDER_FOUND);
    IndexService test = createIndex("test");
    shardId = new ShardId(test.index(), 0);
    assertTrue(test.hasShard(0));
    assertEquals("shard is allocated", indicesService.canDeleteShardContent(shardId, test.getIndexSettings()), ShardDeletionCheckResult.STILL_ALLOCATED);
    test.removeShard(0, "boom");
    assertEquals("shard is removed", indicesService.canDeleteShardContent(shardId, test.getIndexSettings()), ShardDeletionCheckResult.FOLDER_FOUND_CAN_DELETE);
    ShardId notAllocated = new ShardId(test.index(), 100);
    assertEquals("shard that was never on this node should NOT be deletable", indicesService.canDeleteShardContent(notAllocated, test.getIndexSettings()), ShardDeletionCheckResult.NO_FOLDER_FOUND);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexService(org.elasticsearch.index.IndexService) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 34 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 settings, IndexScopedSettings indexScopedSettings) {
    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(settings).build();
    IndexMetaData metaData = IndexMetaData.builder(index.getName()).settings(build).build();
    return new IndexSettings(metaData, Settings.EMPTY, indexScopedSettings);
}
Also used : 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)

Example 35 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)

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