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