Search in sources :

Example 16 with MappingMetaData

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

the class PartitionedTableIntegrationTest method testAlterPartitionedTableKeepsMetadata.

@Test
public void testAlterPartitionedTableKeepsMetadata() throws Exception {
    execute("create table dynamic_table (" + "  id integer, " + "  score double" + ") partitioned by (score) with (number_of_replicas=0, column_policy='dynamic')");
    ensureGreen();
    execute("insert into dynamic_table (id, score) values (1, 10)");
    execute("refresh table dynamic_table");
    ensureGreen();
    MappingMetaData partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("dynamic_table", Collections.singletonList(new BytesRef("10.0"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
    Map<String, Object> metaMap = (Map) partitionMetaData.getSourceAsMap().get("_meta");
    assertThat(String.valueOf(metaMap.get("partitioned_by")), Matchers.is("[[score, double]]"));
    execute("alter table dynamic_table set (column_policy= 'dynamic')");
    waitNoPendingTasksOnAll();
    partitionMetaData = clusterService().state().metaData().indices().get(new PartitionName("dynamic_table", Collections.singletonList(new BytesRef("10.0"))).asIndexName()).getMappings().get(Constants.DEFAULT_MAPPING_TYPE);
    metaMap = (Map) partitionMetaData.getSourceAsMap().get("_meta");
    assertThat(String.valueOf(metaMap.get("partitioned_by")), Matchers.is("[[score, double]]"));
}
Also used : PartitionName(io.crate.metadata.PartitionName) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test)

Example 17 with MappingMetaData

use of org.elasticsearch.cluster.metadata.MappingMetaData in project sonarqube by SonarSource.

the class IndexCreatorTest method create_index.

@Test
public void create_index() throws Exception {
    assertThat(mappings()).isEmpty();
    IndexDefinitions registry = new IndexDefinitions(new IndexDefinition[] { new FakeIndexDefinition() }, new MapSettings());
    registry.start();
    IndexCreator creator = new IndexCreator(es.client(), registry);
    creator.start();
    // check that index is created with related mapping
    ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = mappings();
    MappingMetaData mapping = mappings.get("fakes").get("fake");
    assertThat(mapping.type()).isEqualTo("fake");
    assertThat(mapping.getSourceAsMap()).isNotEmpty();
    assertThat(countMappingFields(mapping)).isEqualTo(2);
    assertThat(field(mapping, "updatedAt").get("type")).isEqualTo("date");
    assertThat(setting("fakes", "index.sonar_hash")).isNotEmpty();
    // of course do not delete indices on stop
    creator.stop();
    assertThat(mappings()).isNotEmpty();
}
Also used : MapSettings(org.sonar.api.config.MapSettings) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) Test(org.junit.Test)

Example 18 with MappingMetaData

use of org.elasticsearch.cluster.metadata.MappingMetaData in project elasticsearch-skywalker by jprante.

the class MetaDataToXContent method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.field("version", metadata.version());
    builder.field("numberOfShards", metadata.numberOfShards());
    builder.startArray("concreteIndices");
    for (String index : metadata.concreteAllIndices()) {
        builder.value(index);
    }
    builder.endArray();
    ImmutableOpenMap<String, ImmutableOpenMap<String, AliasMetaData>> aliases = metadata.getAliases();
    builder.startArray("aliases");
    for (ObjectCursor<String> alias : aliases.keys()) {
        builder.startObject(alias.value);
        builder.startArray("aliasMetadata");
        for (ObjectCursor<String> s : aliases.get(alias.value).keys()) {
            builder.startObject();
            AliasMetaData amd = aliases.get(alias.value).get(s.value);
            builder.field("alias", amd.getAlias());
            builder.field("filter", amd.getFilter().string());
            builder.field("indexRouting", amd.getIndexRouting());
            builder.field("searchRouting", amd.getSearchRouting());
            builder.endObject();
        }
        builder.endArray();
        builder.endObject();
    }
    builder.endArray();
    builder.startArray("indexes");
    ImmutableOpenMap<String, IndexMetaData> indices = metadata.getIndices();
    for (ObjectCursor<String> s : indices.keys()) {
        IndexMetaData imd = indices.get(s.value);
        builder.startObject();
        builder.field("index", imd.getIndex());
        builder.field("state", imd.getState().name());
        builder.field("numberOfReplicas", imd.getNumberOfReplicas());
        builder.field("numberOfShards", imd.getNumberOfShards());
        builder.field("totalNumberOfShards", imd.getTotalNumberOfShards());
        builder.field("version", imd.getVersion());
        builder.field("settings", imd.getSettings().getAsMap());
        ImmutableOpenMap<String, MappingMetaData> m = imd.getMappings();
        // skip mappings here
        builder.endObject();
    }
    builder.endArray();
    builder.startArray("templates");
    ImmutableOpenMap<String, IndexTemplateMetaData> templates = metadata.getTemplates();
    for (ObjectCursor<String> s : templates.keys()) {
        IndexTemplateMetaData itmd = templates.get(s.value);
        itmd.getName();
        itmd.getOrder();
        itmd.getTemplate();
        itmd.getSettings();
        itmd.getMappings();
    }
    builder.endArray();
    builder.endObject();
    return builder;
}
Also used : AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) MappingMetaData(org.elasticsearch.cluster.metadata.MappingMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 19 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 20 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)

Aggregations

MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)46 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)16 Map (java.util.Map)15 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 HashMap (java.util.HashMap)7 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)7 PartitionName (io.crate.metadata.PartitionName)6 BytesRef (org.apache.lucene.util.BytesRef)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)5 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 List (java.util.List)3 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)3