Search in sources :

Example 6 with MappingMetadata

use of org.elasticsearch.cluster.metadata.MappingMetadata in project crate by crate.

the class CrateMetaDataUpgradeService method upgradeIndexMapping.

private IndexMetaData upgradeIndexMapping(IndexMetaData indexMetaData) throws IOException {
    MappingMetaData mappingMetaData = indexMetaData.mapping(Constants.DEFAULT_MAPPING_TYPE);
    MappingMetaData newMappingMetaData = saveRoutingHashFunctionToMapping(mappingMetaData, indexMetaData.getSettings().get(IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION));
    if (mappingMetaData != newMappingMetaData) {
        logger.info("upgraded mapping of index={}", indexMetaData.getIndex());
        IndexMetaData.Builder builder = IndexMetaData.builder(indexMetaData).removeMapping(Constants.DEFAULT_MAPPING_TYPE).putMapping(newMappingMetaData);
        // partitions with the same index UUID when created during a bulk insert.
        if (PartitionName.isPartition(indexMetaData.getIndex())) {
            String indexName = indexMetaData.getIndex();
            String newUUID = Strings.randomBase64UUID();
            builder.settings(Settings.builder().put(indexMetaData.getSettings()).put(IndexMetaData.SETTING_INDEX_UUID, newUUID));
            logger.info("new UUID={} was set for index index={}", newUUID, indexName);
            upgradeShardMetaData(nodeEnv, indexName, newUUID, logger);
        }
        return builder.build();
    }
    return indexMetaData;
}
Also used : MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 7 with MappingMetadata

use of org.elasticsearch.cluster.metadata.MappingMetadata in project crate by crate.

the class CrateMetaDataUpgradeService method upgradeTemplateMapping.

private IndexTemplateMetaData upgradeTemplateMapping(IndexTemplateMetaData indexTemplateMetaData) throws IOException {
    // we only want to upgrade partition table related templates
    if (PartitionName.isPartition(indexTemplateMetaData.getTemplate()) == false) {
        return indexTemplateMetaData;
    }
    MappingMetaData mappingMetaData = new MappingMetaData(indexTemplateMetaData.getMappings().get(Constants.DEFAULT_MAPPING_TYPE));
    MappingMetaData newMappingMetaData = saveRoutingHashFunctionToMapping(mappingMetaData, indexTemplateMetaData.getSettings().get(IndexMetaData.SETTING_LEGACY_ROUTING_HASH_FUNCTION));
    if (mappingMetaData != newMappingMetaData) {
        logger.info("upgraded mapping of template={}", indexTemplateMetaData.getName());
        return new IndexTemplateMetaData.Builder(indexTemplateMetaData).removeMapping(Constants.DEFAULT_MAPPING_TYPE).putMapping(Constants.DEFAULT_MAPPING_TYPE, newMappingMetaData.source()).build();
    }
    return indexTemplateMetaData;
}
Also used : IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData)

Example 8 with MappingMetadata

use of org.elasticsearch.cluster.metadata.MappingMetadata in project crate by crate.

the class DocIndexMetaDataTest method getIndexMetaData.

private IndexMetaData getIndexMetaData(String indexName, XContentBuilder builder, Settings settings, @Nullable AliasMetaData aliasMetaData) throws IOException {
    Map<String, Object> mappingSource = XContentHelper.convertToMap(builder.bytes(), true).v2();
    mappingSource = sortProperties(mappingSource);
    Settings.Builder settingsBuilder = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.version.created", org.elasticsearch.Version.CURRENT).put(settings);
    IndexMetaData.Builder mdBuilder = IndexMetaData.builder(indexName).settings(settingsBuilder).putMapping(new MappingMetaData(Constants.DEFAULT_MAPPING_TYPE, mappingSource));
    if (aliasMetaData != null) {
        mdBuilder.putAlias(aliasMetaData);
    }
    return mdBuilder.build();
}
Also used : MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Settings(org.elasticsearch.common.settings.Settings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 9 with MappingMetadata

use of org.elasticsearch.cluster.metadata.MappingMetadata in project crate by crate.

the class DocIndexMetaDataTest method getDocIndexMetaDataFromStatement.

private DocIndexMetaData getDocIndexMetaDataFromStatement(String stmt) throws IOException {
    Statement statement = SqlParser.createStatement(stmt);
    ClusterService clusterService = new NoopClusterService();
    final TransportPutIndexTemplateAction transportPutIndexTemplateAction = mock(TransportPutIndexTemplateAction.class);
    Provider<TransportPutIndexTemplateAction> indexTemplateActionProvider = new Provider<TransportPutIndexTemplateAction>() {

        @Override
        public TransportPutIndexTemplateAction get() {
            return transportPutIndexTemplateAction;
        }
    };
    DocTableInfoFactory docTableInfoFactory = new InternalDocTableInfoFactory(functions, new IndexNameExpressionResolver(Settings.EMPTY), indexTemplateActionProvider, executorService);
    DocSchemaInfo docSchemaInfo = new DocSchemaInfo(Schemas.DEFAULT_SCHEMA_NAME, clusterService, docTableInfoFactory);
    CreateTableStatementAnalyzer analyzer = new CreateTableStatementAnalyzer(new Schemas(Settings.EMPTY, ImmutableMap.<String, SchemaInfo>of("doc", docSchemaInfo), clusterService, new DocSchemaInfoFactory(docTableInfoFactory)), new FulltextAnalyzerResolver(clusterService, new IndicesAnalysisService(Settings.EMPTY)), functions, new NumberOfShards(clusterService));
    Analysis analysis = new Analysis(SessionContext.SYSTEM_SESSION, ParameterContext.EMPTY, ParamTypeHints.EMPTY);
    CreateTableAnalyzedStatement analyzedStatement = analyzer.analyze((CreateTable) statement, analysis.parameterContext(), analysis.sessionContext());
    Settings.Builder settingsBuilder = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.version.created", org.elasticsearch.Version.CURRENT).put(analyzedStatement.tableParameter().settings());
    IndexMetaData indexMetaData = IndexMetaData.builder(analyzedStatement.tableIdent().name()).settings(settingsBuilder).putMapping(new MappingMetaData(Constants.DEFAULT_MAPPING_TYPE, analyzedStatement.mapping())).build();
    return newMeta(indexMetaData, analyzedStatement.tableIdent().name());
}
Also used : IndicesAnalysisService(org.elasticsearch.indices.analysis.IndicesAnalysisService) Statement(io.crate.sql.tree.Statement) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Provider(org.elasticsearch.common.inject.Provider) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) TransportPutIndexTemplateAction(org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Settings(org.elasticsearch.common.settings.Settings) SchemaInfo(io.crate.metadata.table.SchemaInfo)

Example 10 with MappingMetadata

use of org.elasticsearch.cluster.metadata.MappingMetadata in project rssriver by dadoonet.

the class RssRiver method isMappingExist.

/**
     * Check if a mapping already exists in an index
     * @param index Index name
     * @param type Mapping name
     * @return true if mapping exists
     */
private boolean isMappingExist(String index, String type) {
    ClusterState cs = client.admin().cluster().prepareState().setIndices(index).execute().actionGet().getState();
    IndexMetaData imd = cs.getMetaData().index(index);
    if (imd == null)
        return false;
    MappingMetaData mdd = imd.mapping(type);
    if (mdd != null)
        return true;
    return false;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)45 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)15 Map (java.util.Map)14 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)11 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)10 Settings (org.elasticsearch.common.settings.Settings)9 Test (org.junit.Test)9 IOException (java.io.IOException)8 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)7 PartitionName (io.crate.metadata.PartitionName)6 HashMap (java.util.HashMap)6 BytesRef (org.apache.lucene.util.BytesRef)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)5 List (java.util.List)4 Set (java.util.Set)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)4 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)3 ArrayList (java.util.ArrayList)3 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)3