Search in sources :

Example 71 with IndexSettings

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

the class FieldDataCacheTests method createIndexSettings.

private IndexSettings createIndexSettings() {
    Settings settings = Settings.EMPTY;
    IndexMetaData indexMetaData = IndexMetaData.builder("_name").settings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)).numberOfShards(1).numberOfReplicas(0).creationDate(System.currentTimeMillis()).build();
    return new IndexSettings(indexMetaData, settings);
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 72 with IndexSettings

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

the class IndicesLifecycleListenerSingleNodeTests method testStartDeleteIndexEventCallback.

public void testStartDeleteIndexEventCallback() throws Throwable {
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    assertAcked(client().admin().indices().prepareCreate("test").setSettings(SETTING_NUMBER_OF_SHARDS, 1, SETTING_NUMBER_OF_REPLICAS, 0));
    ensureGreen();
    Index idx = resolveIndex("test");
    IndexMetaData metaData = indicesService.indexService(idx).getMetaData();
    ShardRouting shardRouting = indicesService.indexService(idx).getShard(0).routingEntry();
    final AtomicInteger counter = new AtomicInteger(1);
    IndexEventListener countingListener = new IndexEventListener() {

        @Override
        public void beforeIndexCreated(Index index, Settings indexSettings) {
            assertEquals("test", index.getName());
            assertEquals(1, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexCreated(IndexService indexService) {
            assertEquals("test", indexService.index().getName());
            assertEquals(2, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexShardCreated(ShardId shardId, Settings indexSettings) {
            assertEquals(3, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardCreated(IndexShard indexShard) {
            assertEquals(4, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardStarted(IndexShard indexShard) {
            assertEquals(5, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexRemoved(IndexService indexService, IndexRemovalReason reason) {
            assertEquals(DELETED, reason);
            assertEquals(6, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void beforeIndexShardDeleted(ShardId shardId, Settings indexSettings) {
            assertEquals(7, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexShardDeleted(ShardId shardId, Settings indexSettings) {
            assertEquals(8, counter.get());
            counter.incrementAndGet();
        }

        @Override
        public void afterIndexRemoved(Index index, IndexSettings indexSettings, IndexRemovalReason reason) {
            assertEquals(DELETED, reason);
            assertEquals(9, counter.get());
            counter.incrementAndGet();
        }
    };
    indicesService.removeIndex(idx, DELETED, "simon says");
    try {
        IndexService index = indicesService.createIndex(metaData, Arrays.asList(countingListener), s -> {
        });
        assertEquals(3, counter.get());
        idx = index.index();
        ShardRouting newRouting = shardRouting;
        String nodeId = newRouting.currentNodeId();
        UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "boom");
        newRouting = newRouting.moveToUnassigned(unassignedInfo).updateUnassigned(unassignedInfo, RecoverySource.StoreRecoverySource.EMPTY_STORE_INSTANCE);
        newRouting = ShardRoutingHelper.initialize(newRouting, nodeId);
        IndexShard shard = index.createShard(newRouting);
        shard.updateRoutingEntry(newRouting);
        assertEquals(5, counter.get());
        final DiscoveryNode localNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
        shard.markAsRecovering("store", new RecoveryState(newRouting, localNode, null));
        shard.recoverFromStore();
        newRouting = ShardRoutingHelper.moveToStarted(newRouting);
        shard.updateRoutingEntry(newRouting);
        assertEquals(6, counter.get());
    } finally {
        indicesService.removeIndex(idx, DELETED, "simon says");
    }
    assertEquals(10, counter.get());
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IndexService(org.elasticsearch.index.IndexService) UnassignedInfo(org.elasticsearch.cluster.routing.UnassignedInfo) IndexShard(org.elasticsearch.index.shard.IndexShard) IndexSettings(org.elasticsearch.index.IndexSettings) Index(org.elasticsearch.index.Index) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ShardId(org.elasticsearch.index.shard.ShardId) IndexEventListener(org.elasticsearch.index.shard.IndexEventListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IndexRemovalReason(org.elasticsearch.indices.cluster.IndicesClusterStateService.AllocatedIndices.IndexRemovalReason) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 73 with IndexSettings

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

the class IndicesServiceTests method testCanDeleteIndexContent.

public void testCanDeleteIndexContent() throws IOException {
    final IndicesService indicesService = getIndicesService();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("test", Settings.builder().put(IndexMetaData.SETTING_SHADOW_REPLICAS, true).put(IndexMetaData.SETTING_DATA_PATH, "/foo/bar").put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 4)).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, randomIntBetween(0, 3)).build());
    assertFalse("shard on shared filesystem", indicesService.canDeleteIndexContents(idxSettings.getIndex(), idxSettings));
    final IndexMetaData.Builder newIndexMetaData = IndexMetaData.builder(idxSettings.getIndexMetaData());
    newIndexMetaData.state(IndexMetaData.State.CLOSE);
    idxSettings = IndexSettingsModule.newIndexSettings(newIndexMetaData.build());
    assertTrue("shard on shared filesystem, but closed, so it should be deletable", indicesService.canDeleteIndexContents(idxSettings.getIndex(), idxSettings));
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 74 with IndexSettings

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

the class IndexShardTestCase method newShard.

/**
     * creates a new initializing shard.
     *
     * @param routing              shard routing to use
     * @param shardPath            path to use for shard data
     * @param indexMetaData        indexMetaData for the shard, including any mapping
     * @param indexSearcherWrapper an optional wrapper to be used during searchers
     * @param listeners            an optional set of listeners to add to the shard
     */
protected IndexShard newShard(ShardRouting routing, ShardPath shardPath, IndexMetaData indexMetaData, @Nullable IndexSearcherWrapper indexSearcherWrapper, Runnable globalCheckpointSyncer, @Nullable EngineFactory engineFactory, IndexingOperationListener... listeners) throws IOException {
    final Settings nodeSettings = Settings.builder().put("node.name", routing.currentNodeId()).build();
    final IndexSettings indexSettings = new IndexSettings(indexMetaData, nodeSettings);
    final IndexShard indexShard;
    final Store store = createStore(indexSettings, shardPath);
    boolean success = false;
    try {
        IndexCache indexCache = new IndexCache(indexSettings, new DisabledQueryCache(indexSettings), null);
        MapperService mapperService = MapperTestUtils.newMapperService(xContentRegistry(), createTempDir(), indexSettings.getSettings());
        mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY, true);
        SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap());
        final IndexEventListener indexEventListener = new IndexEventListener() {
        };
        final Engine.Warmer warmer = searcher -> {
        };
        IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(nodeSettings, new IndexFieldDataCache.Listener() {
        });
        IndexFieldDataService indexFieldDataService = new IndexFieldDataService(indexSettings, indicesFieldDataCache, new NoneCircuitBreakerService(), mapperService);
        indexShard = new IndexShard(routing, indexSettings, shardPath, store, indexCache, mapperService, similarityService, indexFieldDataService, engineFactory, indexEventListener, indexSearcherWrapper, threadPool, BigArrays.NON_RECYCLING_INSTANCE, warmer, globalCheckpointSyncer, Collections.emptyList(), Arrays.asList(listeners));
        success = true;
    } finally {
        if (success == false) {
            IOUtils.close(store);
        }
    }
    return indexShard;
}
Also used : IndexNotFoundException(org.apache.lucene.index.IndexNotFoundException) Versions(org.elasticsearch.common.lucene.uid.Versions) ByteSizeUnit(org.elasticsearch.common.unit.ByteSizeUnit) Arrays(java.util.Arrays) Nullable(org.elasticsearch.common.Nullable) BigArrays(org.elasticsearch.common.util.BigArrays) BiFunction(java.util.function.BiFunction) VersionType(org.elasticsearch.index.VersionType) Document(org.apache.lucene.document.Document) IndexRequest(org.elasticsearch.action.index.IndexRequest) Settings(org.elasticsearch.common.settings.Settings) ShardRoutingHelper(org.elasticsearch.cluster.routing.ShardRoutingHelper) Directory(org.apache.lucene.store.Directory) ThreadPool(org.elasticsearch.threadpool.ThreadPool) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) UidFieldMapper(org.elasticsearch.index.mapper.UidFieldMapper) EnumSet(java.util.EnumSet) PeerRecoveryTargetService(org.elasticsearch.indices.recovery.PeerRecoveryTargetService) Set(java.util.Set) MapperTestUtils(org.elasticsearch.index.MapperTestUtils) Engine(org.elasticsearch.index.engine.Engine) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) RecoverySource(org.elasticsearch.cluster.routing.RecoverySource) MapperService(org.elasticsearch.index.mapper.MapperService) Version(org.elasticsearch.Version) Matchers.contains(org.hamcrest.Matchers.contains) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState) LeafReader(org.apache.lucene.index.LeafReader) TestShardRouting(org.elasticsearch.cluster.routing.TestShardRouting) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting) StartRecoveryRequest(org.elasticsearch.indices.recovery.StartRecoveryRequest) XContentType(org.elasticsearch.common.xcontent.XContentType) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) RecoveryFailedException(org.elasticsearch.indices.recovery.RecoveryFailedException) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) BytesArray(org.elasticsearch.common.bytes.BytesArray) RecoverySourceHandler(org.elasticsearch.indices.recovery.RecoverySourceHandler) HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) IndexCache(org.elasticsearch.index.cache.IndexCache) SequenceNumbersService(org.elasticsearch.index.seqno.SequenceNumbersService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Store(org.elasticsearch.index.store.Store) IndexSettings(org.elasticsearch.index.IndexSettings) Node(org.elasticsearch.node.Node) Matchers.hasSize(org.hamcrest.Matchers.hasSize) ESTestCase(org.elasticsearch.test.ESTestCase) Bits(org.apache.lucene.util.Bits) SourceToParse(org.elasticsearch.index.mapper.SourceToParse) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) Uid(org.elasticsearch.index.mapper.Uid) RecoveryTarget(org.elasticsearch.indices.recovery.RecoveryTarget) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) DirectoryService(org.elasticsearch.index.store.DirectoryService) EngineFactory(org.elasticsearch.index.engine.EngineFactory) TimeUnit(java.util.concurrent.TimeUnit) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) DummyShardLock(org.elasticsearch.test.DummyShardLock) Collections(java.util.Collections) IndexSettings(org.elasticsearch.index.IndexSettings) Store(org.elasticsearch.index.store.Store) IndexFieldDataCache(org.elasticsearch.index.fielddata.IndexFieldDataCache) IndicesFieldDataCache(org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) IndexCache(org.elasticsearch.index.cache.IndexCache) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) DisabledQueryCache(org.elasticsearch.index.cache.query.DisabledQueryCache) MapperService(org.elasticsearch.index.mapper.MapperService) Engine(org.elasticsearch.index.engine.Engine) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 75 with IndexSettings

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

the class HighlightBuilderTests method testBuildSearchContextHighlight.

/**
     * test that build() outputs a {@link SearchContextHighlight} that is has similar parameters
     * than what we have in the random {@link HighlightBuilder}
     */
public void testBuildSearchContextHighlight() throws IOException {
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
    Index index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, indexSettings);
    // shard context will only need indicesQueriesRegistry for building Query objects nested in highlighter
    QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(), null, null, System::currentTimeMillis) {

        @Override
        public MappedFieldType fieldMapper(String name) {
            TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name);
            return builder.build(new Mapper.BuilderContext(idxSettings.getSettings(), new ContentPath(1))).fieldType();
        }
    };
    mockShardContext.setMapUnmappedFieldAsString(true);
    for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
        HighlightBuilder highlightBuilder = randomHighlighterBuilder();
        SearchContextHighlight highlight = highlightBuilder.build(mockShardContext);
        for (SearchContextHighlight.Field field : highlight.fields()) {
            String encoder = highlightBuilder.encoder() != null ? highlightBuilder.encoder() : HighlightBuilder.DEFAULT_ENCODER;
            assertEquals(encoder, field.fieldOptions().encoder());
            final Field fieldBuilder = getFieldBuilderByName(highlightBuilder, field.field());
            assertNotNull("expected a highlight builder for field " + field.field(), fieldBuilder);
            FieldOptions fieldOptions = field.fieldOptions();
            BiConsumer<Function<AbstractHighlighterBuilder<?>, Object>, Function<FieldOptions, Object>> checkSame = mergeBeforeChek(highlightBuilder, fieldBuilder, fieldOptions);
            checkSame.accept(AbstractHighlighterBuilder::boundaryChars, FieldOptions::boundaryChars);
            checkSame.accept(AbstractHighlighterBuilder::boundaryScannerType, FieldOptions::boundaryScannerType);
            checkSame.accept(AbstractHighlighterBuilder::boundaryMaxScan, FieldOptions::boundaryMaxScan);
            checkSame.accept(AbstractHighlighterBuilder::fragmentSize, FieldOptions::fragmentCharSize);
            checkSame.accept(AbstractHighlighterBuilder::fragmenter, FieldOptions::fragmenter);
            checkSame.accept(AbstractHighlighterBuilder::requireFieldMatch, FieldOptions::requireFieldMatch);
            checkSame.accept(AbstractHighlighterBuilder::noMatchSize, FieldOptions::noMatchSize);
            checkSame.accept(AbstractHighlighterBuilder::numOfFragments, FieldOptions::numberOfFragments);
            checkSame.accept(AbstractHighlighterBuilder::phraseLimit, FieldOptions::phraseLimit);
            checkSame.accept(AbstractHighlighterBuilder::highlighterType, FieldOptions::highlighterType);
            checkSame.accept(AbstractHighlighterBuilder::highlightFilter, FieldOptions::highlightFilter);
            checkSame.accept(AbstractHighlighterBuilder::preTags, FieldOptions::preTags);
            checkSame.accept(AbstractHighlighterBuilder::postTags, FieldOptions::postTags);
            checkSame.accept(AbstractHighlighterBuilder::options, FieldOptions::options);
            checkSame.accept(AbstractHighlighterBuilder::order, op -> op.scoreOrdered() ? Order.SCORE : Order.NONE);
            assertEquals(fieldBuilder.fragmentOffset, fieldOptions.fragmentOffset());
            if (fieldBuilder.matchedFields != null) {
                String[] copy = Arrays.copyOf(fieldBuilder.matchedFields, fieldBuilder.matchedFields.length);
                Arrays.sort(copy);
                assertArrayEquals(copy, new TreeSet<>(fieldOptions.matchedFields()).toArray(new String[fieldOptions.matchedFields().size()]));
            } else {
                assertNull(fieldOptions.matchedFields());
            }
            Query expectedValue = null;
            if (fieldBuilder.highlightQuery != null) {
                expectedValue = QueryBuilder.rewriteQuery(fieldBuilder.highlightQuery, mockShardContext).toQuery(mockShardContext);
            } else if (highlightBuilder.highlightQuery != null) {
                expectedValue = QueryBuilder.rewriteQuery(highlightBuilder.highlightQuery, mockShardContext).toQuery(mockShardContext);
            }
            assertEquals(expectedValue, fieldOptions.highlightQuery());
        }
    }
}
Also used : Query(org.apache.lucene.search.Query) IndexSettings(org.elasticsearch.index.IndexSettings) IdsQueryBuilder(org.elasticsearch.index.query.IdsQueryBuilder) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) MatchAllQueryBuilder(org.elasticsearch.index.query.MatchAllQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) TermQueryBuilder(org.elasticsearch.index.query.TermQueryBuilder) FieldOptions(org.elasticsearch.search.fetch.subphase.highlight.SearchContextHighlight.FieldOptions) Index(org.elasticsearch.index.Index) ContentPath(org.elasticsearch.index.mapper.ContentPath) Field(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder.Field) Function(java.util.function.Function) TreeSet(java.util.TreeSet) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) TextFieldMapper(org.elasticsearch.index.mapper.TextFieldMapper)

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