Search in sources :

Example 66 with IndexSettings

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

the class SimilarityServiceTests method testDefaultSimilarity.

public void testDefaultSimilarity() {
    Settings settings = Settings.builder().build();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("test", settings);
    SimilarityService service = new SimilarityService(indexSettings, Collections.emptyMap());
    assertThat(service.getDefaultSimilarity(), instanceOf(BM25Similarity.class));
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) BM25Similarity(org.apache.lucene.search.similarities.BM25Similarity) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 67 with IndexSettings

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

the class ExtendedBoundsTests method testParseAndValidate.

public void testParseAndValidate() {
    long now = randomLong();
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
    SearchContext context = mock(SearchContext.class);
    QueryShardContext qsc = new QueryShardContext(0, new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings), null, null, null, null, null, xContentRegistry(), null, null, () -> now);
    when(context.getQueryShardContext()).thenReturn(qsc);
    FormatDateTimeFormatter formatter = Joda.forPattern("dateOptionalTime");
    DocValueFormat format = new DocValueFormat.DateTime(formatter, DateTimeZone.UTC);
    ExtendedBounds expected = randomParsedExtendedBounds();
    ExtendedBounds parsed = unparsed(expected).parseAndValidate("test", context, format);
    // parsed won't *equal* expected because equal includes the String parts
    assertEquals(expected.getMin(), parsed.getMin());
    assertEquals(expected.getMax(), parsed.getMax());
    parsed = new ExtendedBounds("now", null).parseAndValidate("test", context, format);
    assertEquals(now, (long) parsed.getMin());
    assertNull(parsed.getMax());
    parsed = new ExtendedBounds(null, "now").parseAndValidate("test", context, format);
    assertNull(parsed.getMin());
    assertEquals(now, (long) parsed.getMax());
    SearchParseException e = expectThrows(SearchParseException.class, () -> new ExtendedBounds(100L, 90L).parseAndValidate("test", context, format));
    assertEquals("[extended_bounds.min][100] cannot be greater than [extended_bounds.max][90] for histogram aggregation [test]", e.getMessage());
    e = expectThrows(SearchParseException.class, () -> unparsed(new ExtendedBounds(100L, 90L)).parseAndValidate("test", context, format));
    assertEquals("[extended_bounds.min][100] cannot be greater than [extended_bounds.max][90] for histogram aggregation [test]", e.getMessage());
}
Also used : SearchParseException(org.elasticsearch.search.SearchParseException) FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter) DocValueFormat(org.elasticsearch.search.DocValueFormat) IndexSettings(org.elasticsearch.index.IndexSettings) SearchContext(org.elasticsearch.search.internal.SearchContext) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings)

Example 68 with IndexSettings

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

the class InternalEngineTests method testUpgradeOldIndex.

public void testUpgradeOldIndex() throws IOException {
    List<Path> indexes = new ArrayList<>();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(getBwcIndicesPath(), "index-*.zip")) {
        for (Path path : stream) {
            indexes.add(path);
        }
    }
    Collections.shuffle(indexes, random());
    for (Path indexFile : indexes.subList(0, scaledRandomIntBetween(1, indexes.size() / 2))) {
        final String indexName = indexFile.getFileName().toString().replace(".zip", "").toLowerCase(Locale.ROOT);
        Path unzipDir = createTempDir();
        Path unzipDataDir = unzipDir.resolve("data");
        // decompress the index
        try (InputStream stream = Files.newInputStream(indexFile)) {
            TestUtil.unzip(stream, unzipDir);
        }
        // check it is unique
        assertTrue(Files.exists(unzipDataDir));
        Path[] list = filterExtraFSFiles(FileSystemUtils.files(unzipDataDir));
        if (list.length != 1) {
            throw new IllegalStateException("Backwards index must contain exactly one cluster but was " + list.length + " " + Arrays.toString(list));
        }
        // the bwc scripts packs the indices under this path
        Path src = OldIndexUtils.getIndexDir(logger, indexName, indexFile.toString(), list[0]);
        Path translog = src.resolve("0").resolve("translog");
        assertTrue("[" + indexFile + "] missing translog dir: " + translog.toString(), Files.exists(translog));
        Path[] tlogFiles = filterExtraFSFiles(FileSystemUtils.files(translog));
        // ckp & tlog
        assertEquals(Arrays.toString(tlogFiles), tlogFiles.length, 2);
        Path tlogFile = tlogFiles[0].getFileName().toString().endsWith("tlog") ? tlogFiles[0] : tlogFiles[1];
        final long size = Files.size(tlogFile);
        logger.debug("upgrading index {} file: {} size: {}", indexName, tlogFiles[0].getFileName(), size);
        Directory directory = newFSDirectory(src.resolve("0").resolve("index"));
        final IndexMetaData indexMetaData = IndexMetaData.FORMAT.loadLatestState(logger, xContentRegistry(), src);
        final IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexMetaData);
        final Store store = createStore(indexSettings, directory);
        final int iters = randomIntBetween(0, 2);
        int numDocs = -1;
        for (int i = 0; i < iters; i++) {
            // make sure we can restart on an upgraded index
            try (InternalEngine engine = createEngine(indexSettings, store, translog, newMergePolicy())) {
                try (Searcher searcher = engine.acquireSearcher("test")) {
                    if (i > 0) {
                        assertEquals(numDocs, searcher.reader().numDocs());
                    }
                    TopDocs search = searcher.searcher().search(new MatchAllDocsQuery(), 1);
                    numDocs = searcher.reader().numDocs();
                    assertTrue(search.totalHits > 1);
                }
                CommitStats commitStats = engine.commitStats();
                Map<String, String> userData = commitStats.getUserData();
                assertTrue("user data doesn't contain uuid", userData.containsKey(Translog.TRANSLOG_UUID_KEY));
                assertTrue("user data doesn't contain generation key", userData.containsKey(Translog.TRANSLOG_GENERATION_KEY));
                assertFalse("user data contains legacy marker", userData.containsKey("translog_id"));
            }
        }
        try (InternalEngine engine = createEngine(indexSettings, store, translog, newMergePolicy())) {
            if (numDocs == -1) {
                try (Searcher searcher = engine.acquireSearcher("test")) {
                    numDocs = searcher.reader().numDocs();
                }
            }
            final int numExtraDocs = randomIntBetween(1, 10);
            for (int i = 0; i < numExtraDocs; i++) {
                ParsedDocument doc = testParsedDocument("extra" + Integer.toString(i), "test", null, testDocument(), new BytesArray("{}"), null);
                Engine.Index firstIndexRequest = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, Versions.MATCH_DELETED, VersionType.INTERNAL, PRIMARY, System.nanoTime(), -1, false);
                Engine.IndexResult indexResult = engine.index(firstIndexRequest);
                assertThat(indexResult.getVersion(), equalTo(1L));
            }
            engine.refresh("test");
            try (Engine.Searcher searcher = engine.acquireSearcher("test")) {
                TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), randomIntBetween(numDocs, numDocs + numExtraDocs));
                assertThat(topDocs.totalHits, equalTo(numDocs + numExtraDocs));
            }
        }
        IOUtils.close(store, directory);
    }
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) ArrayList(java.util.ArrayList) Store(org.elasticsearch.index.store.Store) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) TopDocs(org.apache.lucene.search.TopDocs) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) Directory(org.apache.lucene.store.Directory) Path(java.nio.file.Path) ContentPath(org.elasticsearch.index.mapper.ContentPath) Searcher(org.elasticsearch.index.engine.Engine.Searcher) BytesArray(org.elasticsearch.common.bytes.BytesArray) InputStream(java.io.InputStream) Searcher(org.elasticsearch.index.engine.Engine.Searcher) IndexSearcher(org.apache.lucene.search.IndexSearcher) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) LongPoint(org.apache.lucene.document.LongPoint) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 69 with IndexSettings

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

the class InternalEngineTests method testForceVersioningNotAllowedExceptForOlderIndices.

public void testForceVersioningNotAllowedExceptForOlderIndices() throws Exception {
    ParsedDocument doc = testParsedDocument("1", "test", null, testDocument(), B_1, null);
    Engine.Index index = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 42, VersionType.FORCE, PRIMARY, 0, -1, false);
    Engine.IndexResult indexResult = engine.index(index);
    assertTrue(indexResult.hasFailure());
    assertThat(indexResult.getFailure(), instanceOf(IllegalArgumentException.class));
    assertThat(indexResult.getFailure().getMessage(), containsString("version type [FORCE] may not be used for indices created after 6.0"));
    IndexSettings oldIndexSettings = IndexSettingsModule.newIndexSettings("test", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_0_0_beta1).build());
    try (Store store = createStore();
        Engine engine = createEngine(oldIndexSettings, store, createTempDir(), NoMergePolicy.INSTANCE)) {
        index = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 84, VersionType.FORCE, PRIMARY, 0, -1, false);
        Engine.IndexResult result = engine.index(index);
        assertTrue(result.hasFailure());
        assertThat(result.getFailure(), instanceOf(IllegalArgumentException.class));
        assertThat(result.getFailure().getMessage(), containsString("version type [FORCE] may not be used for non-translog operations"));
        index = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 84, VersionType.FORCE, Engine.Operation.Origin.LOCAL_TRANSLOG_RECOVERY, 0, -1, false);
        result = engine.index(index);
        assertThat(result.getVersion(), equalTo(84L));
    }
}
Also used : ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) IndexSettings(org.elasticsearch.index.IndexSettings) Store(org.elasticsearch.index.store.Store) Index(org.elasticsearch.index.Index)

Example 70 with IndexSettings

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

the class ShadowEngineTests method createStore.

protected Store createStore(final Directory directory) throws IOException {
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(shardId.getIndex(), Settings.EMPTY);
    final DirectoryService directoryService = new DirectoryService(shardId, indexSettings) {

        @Override
        public Directory newDirectory() throws IOException {
            return directory;
        }
    };
    return new Store(shardId, indexSettings, directoryService, new DummyShardLock(shardId));
}
Also used : IndexSettings(org.elasticsearch.index.IndexSettings) Store(org.elasticsearch.index.store.Store) DirectoryService(org.elasticsearch.index.store.DirectoryService) DummyShardLock(org.elasticsearch.test.DummyShardLock)

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