当前位置: 首页>>代码示例>>Java>>正文


Java IndexMetaData类代码示例

本文整理汇总了Java中org.elasticsearch.cluster.metadata.IndexMetaData的典型用法代码示例。如果您正苦于以下问题:Java IndexMetaData类的具体用法?Java IndexMetaData怎么用?Java IndexMetaData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IndexMetaData类属于org.elasticsearch.cluster.metadata包,在下文中一共展示了IndexMetaData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkIndexClosing

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * Check if any of the indices to be closed are currently being restored from a snapshot and fail closing if such an index
 * is found as closing an index that is being restored makes the index unusable (it cannot be recovered).
 */
public static void checkIndexClosing(ClusterState currentState, Set<IndexMetaData> indices) {
    RestoreInProgress restore = currentState.custom(RestoreInProgress.TYPE);
    if (restore != null) {
        Set<Index> indicesToFail = null;
        for (RestoreInProgress.Entry entry : restore.entries()) {
            for (ObjectObjectCursor<ShardId, RestoreInProgress.ShardRestoreStatus> shard : entry.shards()) {
                if (!shard.value.state().completed()) {
                    IndexMetaData indexMetaData = currentState.metaData().index(shard.key.getIndex());
                    if (indexMetaData != null && indices.contains(indexMetaData)) {
                        if (indicesToFail == null) {
                            indicesToFail = new HashSet<>();
                        }
                        indicesToFail.add(shard.key.getIndex());
                    }
                }
            }
        }
        if (indicesToFail != null) {
            throw new IllegalArgumentException("Cannot close indices that are being restored: " + indicesToFail);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:RestoreService.java

示例2: testPatternCaptureTokenFilter

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testPatternCaptureTokenFilter() throws Exception {
    String json = "/org/elasticsearch/index/analysis/pattern_capture.json";
    Settings settings = Settings.builder()
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .loadFromStream(json, getClass().getResourceAsStream(json))
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();

    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(idxSettings, settings).indexAnalyzers;
    NamedAnalyzer analyzer1 = indexAnalyzers.get("single");

    assertTokenStreamContents(analyzer1.tokenStream("test", "foobarbaz"), new String[]{"foobarbaz","foobar","foo"});

    NamedAnalyzer analyzer2 = indexAnalyzers.get("multi");

    assertTokenStreamContents(analyzer2.tokenStream("test", "abc123def"), new String[]{"abc123def","abc","123","def"});

    NamedAnalyzer analyzer3 = indexAnalyzers.get("preserve");

    assertTokenStreamContents(analyzer3.tokenStream("test", "foobarbaz"), new String[]{"foobar","foo"});
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:PatternCaptureTokenFilterTests.java

示例3: testIndexAndTombstoneWithSameNameOnStartup

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * This test checks an edge case where, if a node had an index (lets call it A with UUID 1), then
 * deleted it (so a tombstone entry for A will exist in the cluster state), then created
 * a new index A with UUID 2, then shutdown, when the node comes back online, it will look at the
 * tombstones for deletions, and it should proceed with trying to delete A with UUID 1 and not
 * throw any errors that the index still exists in the cluster state.  This is a case of ensuring
 * that tombstones that have the same name as current valid indices don't cause confusion by
 * trying to delete an index that exists.
 * See https://github.com/elastic/elasticsearch/issues/18054
 */
public void testIndexAndTombstoneWithSameNameOnStartup() throws Exception {
    final String indexName = "test";
    final Index index = new Index(indexName, UUIDs.randomBase64UUID());
    final IndicesService indicesService = getIndicesService();
    final Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
                                     .put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID())
                                     .build();
    final IndexMetaData indexMetaData = new IndexMetaData.Builder(index.getName())
                                            .settings(idxSettings)
                                            .numberOfShards(1)
                                            .numberOfReplicas(0)
                                            .build();
    final Index tombstonedIndex = new Index(indexName, UUIDs.randomBase64UUID());
    final IndexGraveyard graveyard = IndexGraveyard.builder().addTombstone(tombstonedIndex).build();
    final MetaData metaData = MetaData.builder().put(indexMetaData, true).indexGraveyard(graveyard).build();
    final ClusterState clusterState = new ClusterState.Builder(new ClusterName("testCluster")).metaData(metaData).build();
    // if all goes well, this won't throw an exception, otherwise, it will throw an IllegalStateException
    indicesService.verifyIndexIsDeleted(tombstonedIndex, clusterState);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:IndicesServiceTests.java

示例4: getExpectedShardSize

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * Returns the expected shard size for the given shard or the default value provided if not enough information are available
 * to estimate the shards size.
 */
public static long getExpectedShardSize(ShardRouting shard, RoutingAllocation allocation, long defaultValue) {
    final IndexMetaData metaData = allocation.metaData().getIndexSafe(shard.index());
    final ClusterInfo info = allocation.clusterInfo();
    if (metaData.getMergeSourceIndex() != null && shard.active() == false &&
        shard.recoverySource().getType() == RecoverySource.Type.LOCAL_SHARDS) {
        // in the shrink index case we sum up the source index shards since we basically make a copy of the shard in
        // the worst case
        long targetShardSize = 0;
        final Index mergeSourceIndex = metaData.getMergeSourceIndex();
        final IndexMetaData sourceIndexMeta = allocation.metaData().getIndexSafe(mergeSourceIndex);
        final Set<ShardId> shardIds = IndexMetaData.selectShrinkShards(shard.id(), sourceIndexMeta, metaData.getNumberOfShards());
        for (IndexShardRoutingTable shardRoutingTable : allocation.routingTable().index(mergeSourceIndex.getName())) {
            if (shardIds.contains(shardRoutingTable.shardId())) {
                targetShardSize += info.getShardSize(shardRoutingTable.primaryShard(), 0);
            }
        }
        return targetShardSize == 0 ? defaultValue : targetShardSize;
    } else {
        return info.getShardSize(shard, defaultValue);
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:DiskThresholdDecider.java

示例5: createTestAnalysis

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
private static TestAnalysis createTestAnalysis() throws IOException {
    InputStream empty_dict = KuromojiAnalysisTests.class.getResourceAsStream("empty_user_dict.txt");
    InputStream dict = KuromojiAnalysisTests.class.getResourceAsStream("user_dict.txt");
    Path home = createTempDir();
    Path config = home.resolve("config");
    Files.createDirectory(config);
    Files.copy(empty_dict, config.resolve("empty_user_dict.txt"));
    Files.copy(dict, config.resolve("user_dict.txt"));
    String json = "/org/elasticsearch/index/analysis/kuromoji_analysis.json";

    Settings settings = Settings.builder()
        .loadFromStream(json, KuromojiAnalysisTests.class.getResourceAsStream(json))
        .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
        .build();
    Settings nodeSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), home).build();
    return createTestAnalysis(new Index("test", "_na_"), nodeSettings, settings, new AnalysisKuromojiPlugin());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:KuromojiAnalysisTests.java

示例6: testRolloverWithNewIndexName

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testRolloverWithNewIndexName() throws Exception {
    assertAcked(prepareCreate("test_index").addAlias(new Alias("test_alias")).get());
    index("test_index", "type1", "1", "field", "value");
    flush("test_index");
    final RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias")
        .setNewIndexName("test_new_index").get();
    assertThat(response.getOldIndex(), equalTo("test_index"));
    assertThat(response.getNewIndex(), equalTo("test_new_index"));
    assertThat(response.isDryRun(), equalTo(false));
    assertThat(response.isRolledOver(), equalTo(true));
    assertThat(response.getConditionStatus().size(), equalTo(0));
    final ClusterState state = client().admin().cluster().prepareState().get().getState();
    final IndexMetaData oldIndex = state.metaData().index("test_index");
    assertFalse(oldIndex.getAliases().containsKey("test_alias"));
    final IndexMetaData newIndex = state.metaData().index("test_new_index");
    assertTrue(newIndex.getAliases().containsKey("test_alias"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:RolloverIT.java

示例7: testDefaultsCompoundAnalysis

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testDefaultsCompoundAnalysis() throws Exception {
    String json = "/org/elasticsearch/index/analysis/stop.json";
    Settings settings = Settings.builder()
        .loadFromStream(json, getClass().getResourceAsStream(json))
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .build();
    IndexSettings idxSettings = IndexSettingsModule.newIndexSettings("index", settings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(idxSettings, settings).indexAnalyzers;
    NamedAnalyzer analyzer1 = indexAnalyzers.get("analyzer1");

    assertTokenStreamContents(analyzer1.tokenStream("test", "to be or not to be"), new String[0]);

    NamedAnalyzer analyzer2 = indexAnalyzers.get("analyzer2");

    assertTokenStreamContents(analyzer2.tokenStream("test", "to be or not to be"), new String[0]);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:StopAnalyzerTests.java

示例8: testTypesExistsWithBlocks

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testTypesExistsWithBlocks() throws IOException {
    assertAcked(prepareCreate("ro").addMapping("type1", jsonBuilder().startObject().startObject("type1").endObject().endObject()));
    ensureGreen("ro");

    // Request is not blocked
    for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) {
        try {
            enableIndexBlock("ro", block);
            assertThat(client().admin().indices().prepareTypesExists("ro").setTypes("type1").execute().actionGet().isExists(), equalTo(true));
        } finally {
            disableIndexBlock("ro", block);
        }
    }

    // Request is blocked
    try {
        enableIndexBlock("ro", IndexMetaData.SETTING_BLOCKS_METADATA);
        assertBlocked(client().admin().indices().prepareTypesExists("ro").setTypes("type1"));
    } finally {
        disableIndexBlock("ro", IndexMetaData.SETTING_BLOCKS_METADATA);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TypesExistsIT.java

示例9: testThatAnalyzersAreUsedInMapping

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testThatAnalyzersAreUsedInMapping() throws IOException {
    int randomInt = randomInt(PreBuiltAnalyzers.values().length-1);
    PreBuiltAnalyzers randomPreBuiltAnalyzer = PreBuiltAnalyzers.values()[randomInt];
    String analyzerName = randomPreBuiltAnalyzer.name().toLowerCase(Locale.ROOT);

    Version randomVersion = randomVersion(random());
    Settings indexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, randomVersion).build();

    NamedAnalyzer namedAnalyzer = new PreBuiltAnalyzerProvider(analyzerName, AnalyzerScope.INDEX, randomPreBuiltAnalyzer.getAnalyzer(randomVersion)).get();

    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
            .startObject("properties").startObject("field").field("type", "text").field("analyzer", analyzerName).endObject().endObject()
            .endObject().endObject().string();
    DocumentMapper docMapper = createIndex("test", indexSettings).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));

    FieldMapper fieldMapper = docMapper.mappers().getMapper("field");
    assertThat(fieldMapper.fieldType().searchAnalyzer(), instanceOf(NamedAnalyzer.class));
    NamedAnalyzer fieldMapperNamedAnalyzer = fieldMapper.fieldType().searchAnalyzer();

    assertThat(fieldMapperNamedAnalyzer.analyzer(), is(namedAnalyzer.analyzer()));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:PreBuiltAnalyzerTests.java

示例10: DocIndexMetaData

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public DocIndexMetaData(Functions functions, IndexMetaData metaData, TableIdent ident) throws IOException {
    this.functions = functions;
    this.ident = ident;
    this.metaData = metaData;
    this.isAlias = !metaData.getIndex().equals(ident.indexName());
    this.numberOfShards = metaData.getNumberOfShards();
    Settings settings = metaData.getSettings();
    this.numberOfReplicas = NumberOfReplicas.fromSettings(settings);
    this.aliases = ImmutableSet.copyOf(metaData.getAliases().keys().toArray(String.class));
    this.defaultMappingMetaData = this.metaData.mappingOrDefault(Constants.DEFAULT_MAPPING_TYPE);
    if (defaultMappingMetaData == null) {
        this.defaultMappingMap = ImmutableMap.of();
    } else {
        this.defaultMappingMap = this.defaultMappingMetaData.sourceAsMap();
    }
    this.tableParameters = TableParameterInfo.tableParametersFromIndexMetaData(metaData);

    Map<String, Object> metaMap = getNested(defaultMappingMap, "_meta");
    indicesMap = getNested(metaMap, "indices", ImmutableMap.<String, Object>of());
    partitionedByList = getNested(metaMap, "partitioned_by", ImmutableList.<List<String>>of());
    generatedColumns = getNested(metaMap, "generated_columns", ImmutableMap.<String, String>of());
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:DocIndexMetaData.java

示例11: testRandomRouting

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public void testRandomRouting() {
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test1").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .put(IndexMetaData.builder("test2").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1))
            .build();

    RoutingTable routingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test1"))
            .addAsNew(metaData.index("test2"))
            .build();

    ShardIterator shardIterator = routingTable.index("test1").shard(0).shardsRandomIt();
    ShardRouting shardRouting1 = shardIterator.nextOrNull();
    assertThat(shardRouting1, notNullValue());
    assertThat(shardIterator.nextOrNull(), notNullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());

    shardIterator = routingTable.index("test1").shard(0).shardsRandomIt();
    ShardRouting shardRouting2 = shardIterator.nextOrNull();
    assertThat(shardRouting2, notNullValue());
    ShardRouting shardRouting3 = shardIterator.nextOrNull();
    assertThat(shardRouting3, notNullValue());
    assertThat(shardIterator.nextOrNull(), nullValue());
    assertThat(shardRouting1, not(sameInstance(shardRouting2)));
    assertThat(shardRouting1, sameInstance(shardRouting3));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:RoutingIteratorTests.java

示例12: testIndexMetaDataChange

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * Test the index metadata change check.
 */
public void testIndexMetaDataChange() {
    final int numNodesInCluster = 3;
    final ClusterState state = createState(numNodesInCluster, randomBoolean(), initialIndices);

    // test when its not the same IndexMetaData
    final Index index = initialIndices.get(0);
    final IndexMetaData originalIndexMeta = state.metaData().index(index);
    // make sure the metadata is actually on the cluster state
    assertNotNull("IndexMetaData for " + index + " should exist on the cluster state", originalIndexMeta);
    IndexMetaData newIndexMeta = createIndexMetadata(index, originalIndexMeta.getVersion() + 1);
    assertTrue("IndexMetaData with different version numbers must be considered changed",
        ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, newIndexMeta));

    // test when it doesn't exist
    newIndexMeta = createIndexMetadata(new Index("doesntexist", UUIDs.randomBase64UUID()));
    assertTrue("IndexMetaData that didn't previously exist should be considered changed",
        ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, newIndexMeta));

    // test when its the same IndexMetaData
    assertFalse("IndexMetaData should be the same", ClusterChangedEvent.indexMetaDataChanged(originalIndexMeta, originalIndexMeta));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:ClusterChangedEventTests.java

示例13: testUpgradeCustomDataPath

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:IndexFolderUpgraderTests.java

示例14: writeIndex

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
private void writeIndex(NodeEnvironment nodeEnv, IndexSettings indexSettings,
                        int numIdxFiles, int numTranslogFiles) throws IOException {
    NodeEnvironment.NodePath[] nodePaths = nodeEnv.nodePaths();
    Path[] oldIndexPaths = new Path[nodePaths.length];
    for (int i = 0; i < nodePaths.length; i++) {
        oldIndexPaths[i] = nodePaths[i].indicesPath.resolve(indexSettings.getIndex().getName());
    }
    IndexMetaData.FORMAT.write(indexSettings.getIndexMetaData(), oldIndexPaths);
    for (int id = 0; id < indexSettings.getNumberOfShards(); id++) {
        Path oldIndexPath = randomFrom(oldIndexPaths);
        ShardId shardId = new ShardId(indexSettings.getIndex(), id);
        if (indexSettings.hasCustomDataPath()) {
            Path customIndexPath = nodeEnv.resolveBaseCustomLocation(indexSettings).resolve(indexSettings.getIndex().getName());
            writeShard(shardId, customIndexPath, numIdxFiles, numTranslogFiles);
        } else {
            writeShard(shardId, oldIndexPath, numIdxFiles, numTranslogFiles);
        }
        ShardStateMetaData state = new ShardStateMetaData(true, indexSettings.getUUID(), AllocationId.newInitializing());
        ShardStateMetaData.FORMAT.write(state, oldIndexPath.resolve(String.valueOf(shardId.getId())));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:IndexFolderUpgraderTests.java

示例15: getRelevantIndicesOnDataOnlyNode

import org.elasticsearch.cluster.metadata.IndexMetaData; //导入依赖的package包/类
public static Set<Index> getRelevantIndicesOnDataOnlyNode(ClusterState state, ClusterState previousState, Set<Index> previouslyWrittenIndices) {
    RoutingNode newRoutingNode = state.getRoutingNodes().node(state.nodes().getLocalNodeId());
    if (newRoutingNode == null) {
        throw new IllegalStateException("cluster state does not contain this node - cannot write index meta state");
    }
    Set<Index> indices = new HashSet<>();
    for (ShardRouting routing : newRoutingNode) {
        indices.add(routing.index());
    }
    // we have to check the meta data also: closed indices will not appear in the routing table, but we must still write the state if we have it written on disk previously
    for (IndexMetaData indexMetaData : state.metaData()) {
        boolean isOrWasClosed = indexMetaData.getState().equals(IndexMetaData.State.CLOSE);
        // if the index is open we might still have to write the state if it just transitioned from closed to open
        // so we have to check for that as well.
        IndexMetaData previousMetaData = previousState.metaData().index(indexMetaData.getIndex());
        if (previousMetaData != null) {
            isOrWasClosed = isOrWasClosed || previousMetaData.getState().equals(IndexMetaData.State.CLOSE);
        }
        if (previouslyWrittenIndices.contains(indexMetaData.getIndex()) && isOrWasClosed) {
            indices.add(indexMetaData.getIndex());
        }
    }
    return indices;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:GatewayMetaState.java


注:本文中的org.elasticsearch.cluster.metadata.IndexMetaData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。