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]]"));
}
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();
}
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;
}
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();
}
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());
}
Aggregations