Search in sources :

Example 96 with Index

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

the class ParentFieldMapperTests method testNoParentNullFieldCreatedIfNoParentSpecified.

public void testNoParentNullFieldCreatedIfNoParentSpecified() throws Exception {
    Index index = new Index("_index", "testUUID");
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(index, Settings.EMPTY);
    NamedAnalyzer namedAnalyzer = new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer());
    IndexAnalyzers indexAnalyzers = new IndexAnalyzers(indexSettings, namedAnalyzer, namedAnalyzer, namedAnalyzer, Collections.emptyMap(), Collections.emptyMap());
    SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap());
    MapperService mapperService = new MapperService(indexSettings, indexAnalyzers, xContentRegistry(), similarityService, new IndicesModule(emptyList()).getMapperRegistry(), () -> null);
    XContentBuilder mappingSource = jsonBuilder().startObject().startObject("some_type").startObject("properties").endObject().endObject().endObject();
    mapperService.merge("some_type", new CompressedXContent(mappingSource.string()), MergeReason.MAPPING_UPDATE, false);
    Set<String> allFields = new HashSet<>(mapperService.simpleMatchToIndexNames("*"));
    assertTrue(allFields.contains("_parent"));
    assertFalse(allFields.contains("_parent#null"));
}
Also used : IndicesModule(org.elasticsearch.indices.IndicesModule) NamedAnalyzer(org.elasticsearch.index.analysis.NamedAnalyzer) IndexSettings(org.elasticsearch.index.IndexSettings) Index(org.elasticsearch.index.Index) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) SimilarityService(org.elasticsearch.index.similarity.SimilarityService) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) IndexAnalyzers(org.elasticsearch.index.analysis.IndexAnalyzers) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) HashSet(java.util.HashSet)

Example 97 with Index

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

the class IndexStoreTests method testStoreDirectory.

public void testStoreDirectory() throws IOException {
    Index index = new Index("foo", "fooUUID");
    final Path tempDir = createTempDir().resolve(index.getUUID()).resolve("0");
    // default
    doTestStoreDirectory(index, tempDir, null, IndexModule.Type.FS);
    // explicit directory impls
    for (IndexModule.Type type : IndexModule.Type.values()) {
        doTestStoreDirectory(index, tempDir, type.name().toLowerCase(Locale.ROOT), type);
    }
}
Also used : ShardPath(org.elasticsearch.index.shard.ShardPath) Path(java.nio.file.Path) Index(org.elasticsearch.index.Index) IndexModule(org.elasticsearch.index.IndexModule)

Example 98 with Index

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

the class StoreTests method testCanOpenIndex.

public void testCanOpenIndex() throws IOException {
    final ShardId shardId = new ShardId("index", "_na_", 1);
    IndexWriterConfig iwc = newIndexWriterConfig();
    Path tempDir = createTempDir();
    final BaseDirectoryWrapper dir = newFSDirectory(tempDir);
    assertFalse(Store.canOpenIndex(logger, tempDir, shardId, (id, l) -> new DummyShardLock(id)));
    IndexWriter writer = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(new StringField("id", "1", random().nextBoolean() ? Field.Store.YES : Field.Store.NO));
    writer.addDocument(doc);
    writer.commit();
    writer.close();
    assertTrue(Store.canOpenIndex(logger, tempDir, shardId, (id, l) -> new DummyShardLock(id)));
    DirectoryService directoryService = new DirectoryService(shardId, INDEX_SETTINGS) {

        @Override
        public Directory newDirectory() throws IOException {
            return dir;
        }
    };
    Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId));
    store.markStoreCorrupted(new CorruptIndexException("foo", "bar"));
    assertFalse(Store.canOpenIndex(logger, tempDir, shardId, (id, l) -> new DummyShardLock(id)));
    store.close();
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Path(java.nio.file.Path) IndexNotFoundException(org.apache.lucene.index.IndexNotFoundException) ShardId(org.elasticsearch.index.shard.ShardId) NoMergePolicy(org.apache.lucene.index.NoMergePolicy) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) IndexSettingsModule(org.elasticsearch.test.IndexSettingsModule) Date(java.util.Date) Term(org.apache.lucene.index.Term) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Random(java.util.Random) ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) InputStreamStreamInput(org.elasticsearch.common.io.stream.InputStreamStreamInput) Document(org.apache.lucene.document.Document) Settings(org.elasticsearch.common.settings.Settings) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CodecUtil(org.apache.lucene.codecs.CodecUtil) Directory(org.apache.lucene.store.Directory) Map(java.util.Map) IOContext(org.apache.lucene.store.IOContext) Path(java.nio.file.Path) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) BytesRef(org.apache.lucene.util.BytesRef) DirectoryReader(org.apache.lucene.index.DirectoryReader) UUIDs(org.elasticsearch.common.UUIDs) SegmentInfos(org.apache.lucene.index.SegmentInfos) FileNotFoundException(java.io.FileNotFoundException) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) Engine(org.elasticsearch.index.engine.Engine) IndexWriter(org.apache.lucene.index.IndexWriter) List(java.util.List) SortedDocValuesField(org.apache.lucene.document.SortedDocValuesField) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) Matchers.endsWith(org.hamcrest.Matchers.endsWith) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StringField(org.apache.lucene.document.StringField) TestUtil(org.apache.lucene.util.TestUtil) RAMDirectory(org.apache.lucene.store.RAMDirectory) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) Lucene(org.elasticsearch.common.lucene.Lucene) OutputStreamStreamOutput(org.elasticsearch.common.io.stream.OutputStreamStreamOutput) ArrayList(java.util.ArrayList) BaseDirectoryWrapper(org.apache.lucene.store.BaseDirectoryWrapper) NoDeletionPolicy(org.apache.lucene.index.NoDeletionPolicy) TimeValue(org.elasticsearch.common.unit.TimeValue) IndexSettings(org.elasticsearch.index.IndexSettings) ESTestCase(org.elasticsearch.test.ESTestCase) VersionUtils.randomVersion(org.elasticsearch.test.VersionUtils.randomVersion) IndexOutput(org.apache.lucene.store.IndexOutput) Matchers.empty(org.hamcrest.Matchers.empty) IndexInput(org.apache.lucene.store.IndexInput) Iterator(java.util.Iterator) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) IndexFileNames(org.apache.lucene.index.IndexFileNames) IOUtils(org.apache.lucene.util.IOUtils) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) ShardLock(org.elasticsearch.env.ShardLock) Version(org.apache.lucene.util.Version) ExceptionsHelper(org.elasticsearch.ExceptionsHelper) KeepOnlyLastCommitDeletionPolicy(org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy) Field(org.apache.lucene.document.Field) Translog(org.elasticsearch.index.translog.Translog) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) TextField(org.apache.lucene.document.TextField) DummyShardLock(org.elasticsearch.test.DummyShardLock) TransportNodesListShardStoreMetaData(org.elasticsearch.indices.store.TransportNodesListShardStoreMetaData) IndexWriter(org.apache.lucene.index.IndexWriter) StringField(org.apache.lucene.document.StringField) BaseDirectoryWrapper(org.apache.lucene.store.BaseDirectoryWrapper) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) DummyShardLock(org.elasticsearch.test.DummyShardLock) Document(org.apache.lucene.document.Document) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 99 with Index

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

the class StoreTests method testOnCloseCallback.

public void testOnCloseCallback() throws IOException {
    final ShardId shardId = new ShardId(new Index(randomRealisticUnicodeOfCodepointLengthBetween(1, 10), "_na_"), randomIntBetween(0, 100));
    DirectoryService directoryService = new LuceneManagedDirectoryService(random());
    final AtomicInteger count = new AtomicInteger(0);
    final ShardLock lock = new DummyShardLock(shardId);
    Store store = new Store(shardId, INDEX_SETTINGS, directoryService, lock, theLock -> {
        assertEquals(shardId, theLock.getShardId());
        assertEquals(lock, theLock);
        count.incrementAndGet();
    });
    assertEquals(count.get(), 0);
    final int iters = randomIntBetween(1, 10);
    for (int i = 0; i < iters; i++) {
        store.close();
    }
    assertEquals(count.get(), 1);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Index(org.elasticsearch.index.Index) DummyShardLock(org.elasticsearch.test.DummyShardLock) ShardLock(org.elasticsearch.env.ShardLock) DummyShardLock(org.elasticsearch.test.DummyShardLock)

Example 100 with Index

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

the class CorruptedFileIT method listShardFiles.

public List<Path> listShardFiles(ShardRouting routing) throws IOException {
    NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(routing.currentNodeId()).setFs(true).get();
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    final Index test = state.metaData().index("test").getIndex();
    assertThat(routing.toString(), nodeStatses.getNodes().size(), equalTo(1));
    List<Path> files = new ArrayList<>();
    for (FsInfo.Path info : nodeStatses.getNodes().get(0).getFs()) {
        String path = info.getPath();
        Path file = PathUtils.get(path).resolve("indices/" + test.getUUID() + "/" + Integer.toString(routing.getId()) + "/index");
        if (Files.exists(file)) {
            // multi data path might only have one path in use
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(file)) {
                for (Path item : stream) {
                    files.add(item);
                }
            }
        }
    }
    return files;
}
Also used : NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) FsInfo(org.elasticsearch.monitor.fs.FsInfo) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) CollectionUtils.iterableAsArrayList(org.elasticsearch.common.util.CollectionUtils.iterableAsArrayList) CheckIndex(org.apache.lucene.index.CheckIndex) Index(org.elasticsearch.index.Index)

Aggregations

Index (org.elasticsearch.index.Index)366 ShardId (org.elasticsearch.index.shard.ShardId)108 Settings (org.elasticsearch.common.settings.Settings)95 ClusterState (org.elasticsearch.cluster.ClusterState)88 ArrayList (java.util.ArrayList)79 IOException (java.io.IOException)74 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)65 IndexMetadata (org.elasticsearch.cluster.metadata.IndexMetadata)65 HashMap (java.util.HashMap)61 Map (java.util.Map)61 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)59 List (java.util.List)56 HashSet (java.util.HashSet)50 Path (java.nio.file.Path)45 IndexSettings (org.elasticsearch.index.IndexSettings)44 IndexService (org.elasticsearch.index.IndexService)43 Set (java.util.Set)40 Metadata (org.elasticsearch.cluster.metadata.Metadata)39 ClusterService (org.elasticsearch.cluster.service.ClusterService)39 ActionListener (org.elasticsearch.action.ActionListener)35