org.elasticsearch.cluster.metadata.AliasMetaData Java Examples
The following examples show how to use
org.elasticsearch.cluster.metadata.AliasMetaData.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Templates.java From crate with Apache License 2.0 | 6 votes |
public static IndexTemplateMetaData.Builder copyWithNewName(IndexTemplateMetaData source, RelationName newName) { String targetTemplateName = PartitionName.templateName(newName.schema(), newName.name()); String targetAlias = newName.indexNameOrAlias(); IndexTemplateMetaData.Builder templateBuilder = IndexTemplateMetaData .builder(targetTemplateName) .patterns(Collections.singletonList(PartitionName.templatePrefix(newName.schema(), newName.name()))) .settings(source.settings()) .order(source.order()) .putAlias(AliasMetaData.builder(targetAlias).build()) .version(source.version()); for (ObjectObjectCursor<String, CompressedXContent> mapping : source.mappings()) { try { templateBuilder.putMapping(mapping.key, mapping.value); } catch (IOException e) { throw new RuntimeException(e); } } return templateBuilder; }
Example #2
Source File: GetAliasesIndicesRequestBuilder.java From elasticshell with Apache License 2.0 | 6 votes |
@Override protected XContentBuilder toXContent(ClusterStateRequest request, ClusterStateResponse response, XContentBuilder builder) throws IOException { MetaData metaData = response.getState().metaData(); builder.startObject(); for (IndexMetaData indexMetaData : metaData) { builder.startObject(indexMetaData.index(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject("aliases"); for (AliasMetaData alias : indexMetaData.aliases().values()) { AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS); } builder.endObject(); builder.endObject(); } builder.endObject(); return builder; }
Example #3
Source File: RestAliasAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
private Table buildTable(RestRequest request, GetAliasesResponse response) { Table table = getTableWithHeader(request); for (ObjectObjectCursor<String, List<AliasMetaData>> cursor : response.getAliases()) { String indexName = cursor.key; for (AliasMetaData aliasMetaData : cursor.value) { table.startRow(); table.addCell(aliasMetaData.alias()); table.addCell(indexName); table.addCell(aliasMetaData.filteringRequired() ? "*" : "-"); String indexRouting = Strings.hasLength(aliasMetaData.indexRouting()) ? aliasMetaData.indexRouting() : "-"; table.addCell(indexRouting); String searchRouting = Strings.hasLength(aliasMetaData.searchRouting()) ? aliasMetaData.searchRouting() : "-"; table.addCell(searchRouting); table.endRow(); } } return table; }
Example #4
Source File: GetIndexResponse.java From Elasticsearch with Apache License 2.0 | 6 votes |
GetIndexResponse(String[] indices, ImmutableOpenMap<String, List<IndexWarmersMetaData.Entry>> warmers, ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings, ImmutableOpenMap<String, List<AliasMetaData>> aliases, ImmutableOpenMap<String, Settings> settings) { this.indices = indices; if (warmers != null) { this.warmers = warmers; } if (mappings != null) { this.mappings = mappings; } if (aliases != null) { this.aliases = aliases; } if (settings != null) { this.settings = settings; } }
Example #5
Source File: IndicesAliasesRequest.java From Elasticsearch with Apache License 2.0 | 6 votes |
public String[] concreteAliases(MetaData metaData, String concreteIndex) { if (expandAliasesWildcards()) { //for DELETE we expand the aliases String[] indexAsArray = {concreteIndex}; ImmutableOpenMap<String, List<AliasMetaData>> aliasMetaData = metaData.findAliases(aliases, indexAsArray); List<String> finalAliases = new ArrayList<>(); for (ObjectCursor<List<AliasMetaData>> curAliases : aliasMetaData.values()) { for (AliasMetaData aliasMeta: curAliases.value) { finalAliases.add(aliasMeta.alias()); } } return finalAliases.toArray(new String[finalAliases.size()]); } else { //for add we just return the current aliases return aliases; } }
Example #6
Source File: GetAliasesResponse.java From Elasticsearch with Apache License 2.0 | 6 votes |
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); int size = in.readVInt(); ImmutableOpenMap.Builder<String, List<AliasMetaData>> aliasesBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { String key = in.readString(); int valueSize = in.readVInt(); List<AliasMetaData> value = new ArrayList<>(valueSize); for (int j = 0; j < valueSize; j++) { value.add(AliasMetaData.Builder.readFrom(in)); } aliasesBuilder.put(key, Collections.unmodifiableList(value)); } aliases = aliasesBuilder.build(); }
Example #7
Source File: AlterTableOperation.java From Elasticsearch with Apache License 2.0 | 5 votes |
private ListenableFuture<Long> updateTemplate(Map<String, Object> newMappings, Settings newSettings, TableIdent tableIdent, AbstractDDLAnalyzedStatement statement) { String templateName = PartitionName.templateName(tableIdent.schema(), tableIdent.name()); IndexTemplateMetaData indexTemplateMetaData = clusterService.state().metaData().templates().get(templateName); if (indexTemplateMetaData == null) { return Futures.immediateFailedFuture(new RuntimeException("Template for partitioned table is missing")); } // merge mappings Map<String, Object> mapping = mergeTemplateMapping(indexTemplateMetaData, newMappings); // merge settings Settings.Builder settingsBuilder = Settings.builder(); settingsBuilder.put(indexTemplateMetaData.settings()); settingsBuilder.put(newSettings); PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName) .create(false) .mapping(Constants.DEFAULT_MAPPING_TYPE, mapping) .order(indexTemplateMetaData.order()) .settings(settingsBuilder.build()) .template(indexTemplateMetaData.template()); request.putHeader(LoginUserContext.USER_INFO_KEY, statement.getParameterContext().getLoginUserContext()); for (ObjectObjectCursor<String, AliasMetaData> container : indexTemplateMetaData.aliases()) { Alias alias = new Alias(container.key); request.alias(alias); } SettableFuture<Long> result = SettableFuture.create(); transportActionProvider.transportPutIndexTemplateAction().execute(request, new SettableFutureToNullActionListener<PutIndexTemplateResponse>(result)); return result; }
Example #8
Source File: EsIndexCacheImpl.java From usergrid with Apache License 2.0 | 5 votes |
private String[] getIndexesFromEs(final String aliasName){ final AdminClient adminClient = this.provider.getClient().admin(); //remove write alias, can only have one ImmutableOpenMap<String, List<AliasMetaData>> aliasMap = adminClient.indices().getAliases( new GetAliasesRequest( aliasName ) ).actionGet().getAliases(); return aliasMap.keys().toArray( String.class ); }
Example #9
Source File: BaseClient.java From elasticsearch-helper with Apache License 2.0 | 5 votes |
private Map<String,String> getFilters(GetAliasesResponse getAliasesResponse) { Map<String,String> result = new HashMap<>(); for (ObjectObjectCursor<String, List<AliasMetaData>> object : getAliasesResponse.getAliases()) { List<AliasMetaData> aliasMetaDataList = object.value; for (AliasMetaData aliasMetaData : aliasMetaDataList) { if (aliasMetaData.filteringRequired()) { result.put(aliasMetaData.alias(), new String(aliasMetaData.getFilter().uncompressed())); } else { result.put(aliasMetaData.alias(), null); } } } return result; }
Example #10
Source File: SearchUpdaterImpl.java From stash-codesearch-plugin with Apache License 2.0 | 5 votes |
private String getIndexFromAlias(String alias) { ImmutableOpenMap<String, List<AliasMetaData>> aliasMap = es.getClient().admin().indices().prepareGetAliases(alias).get().getAliases(); for (String index : aliasMap.keys().toArray(String.class)) { for (AliasMetaData aliasEntry : aliasMap.get(index)) { if (aliasEntry.getAlias().equals(alias)) { return index; } } } return null; }
Example #11
Source File: RoutesProvider.java From swagger-for-elasticsearch with Apache License 2.0 | 5 votes |
protected List<String> getAllAliases() { return cache.getOrResolve("getAllAliases", new Callable<List<String>>() { @Override public List<String> call() throws Exception { List<String> allAliases = new ArrayList<String>(); ImmutableOpenMap<String, List<AliasMetaData>> indexAliasesMap = client.admin().indices() .prepareGetAliases() .get() .getAliases(); for (ObjectCursor<List<AliasMetaData>> listObjectCursor : indexAliasesMap.values()) { for (AliasMetaData aliasMetaData : listObjectCursor.value) { if (!allAliases.contains(aliasMetaData.alias())) { allAliases.add(aliasMetaData.alias()); } } } CollectionUtil.sort(allAliases, new Function<String, Comparable>() { @Override public Comparable apply(String s) { return s; } }); return allAliases; } } ); }
Example #12
Source File: GetAliasesResponse.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeVInt(aliases.size()); for (ObjectObjectCursor<String, List<AliasMetaData>> entry : aliases) { out.writeString(entry.key); out.writeVInt(entry.value.size()); for (AliasMetaData aliasMetaData : entry.value) { aliasMetaData.writeTo(out); } } }
Example #13
Source File: TransportGetAliasesAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override protected void masterOperation(GetAliasesRequest request, ClusterState state, ActionListener<GetAliasesResponse> listener) { String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request); @SuppressWarnings("unchecked") ImmutableOpenMap<String, List<AliasMetaData>> result = (ImmutableOpenMap) state.metaData().findAliases(request.aliases(), concreteIndices); listener.onResponse(new GetAliasesResponse(result)); }
Example #14
Source File: RestGetIndicesAliasesAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); final String[] aliases = Strings.splitStringByCommaToArray(request.param("name")); ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest() .routingTable(false) .nodes(false) .indices(indices); clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); client.admin().cluster().state(clusterStateRequest, new RestBuilderListener<ClusterStateResponse>(channel) { @Override public RestResponse buildResponse(ClusterStateResponse response, XContentBuilder builder) throws Exception { MetaData metaData = response.getState().metaData(); builder.startObject(); final boolean isAllAliasesRequested = isAllOrWildcard(aliases); for (IndexMetaData indexMetaData : metaData) { builder.startObject(indexMetaData.getIndex(), XContentBuilder.FieldCaseConversion.NONE); builder.startObject("aliases"); for (ObjectCursor<AliasMetaData> cursor : indexMetaData.getAliases().values()) { if (isAllAliasesRequested || Regex.simpleMatch(aliases, cursor.value.alias())) { AliasMetaData.Builder.toXContent(cursor.value, builder, ToXContent.EMPTY_PARAMS); } } builder.endObject(); builder.endObject(); } builder.endObject(); return new BytesRestResponse(OK, builder); } }); }
Example #15
Source File: RestGetAliasesAction.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) { final String[] aliases = request.paramAsStringArrayOrEmptyIfAll("name"); final String[] indices = Strings.splitStringByCommaToArray(request.param("index")); final GetAliasesRequest getAliasesRequest = new GetAliasesRequest(aliases); getAliasesRequest.indices(indices); getAliasesRequest.indicesOptions(IndicesOptions.fromRequest(request, getAliasesRequest.indicesOptions())); getAliasesRequest.local(request.paramAsBoolean("local", getAliasesRequest.local())); client.admin().indices().getAliases(getAliasesRequest, new RestBuilderListener<GetAliasesResponse>(channel) { @Override public RestResponse buildResponse(GetAliasesResponse response, XContentBuilder builder) throws Exception { // empty body, if indices were specified but no aliases were if (indices.length > 0 && response.getAliases().isEmpty()) { return new BytesRestResponse(OK, builder.startObject().endObject()); } else if (response.getAliases().isEmpty()) { String message = String.format(Locale.ROOT, "alias [%s] missing", toNamesString(getAliasesRequest.aliases())); builder.startObject() .field("error", message) .field("status", RestStatus.NOT_FOUND.getStatus()) .endObject(); return new BytesRestResponse(RestStatus.NOT_FOUND, builder); } builder.startObject(); for (ObjectObjectCursor<String, List<AliasMetaData>> entry : response.getAliases()) { builder.startObject(entry.key, XContentBuilder.FieldCaseConversion.NONE); builder.startObject(Fields.ALIASES); for (AliasMetaData alias : entry.value) { AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS); } builder.endObject(); builder.endObject(); } builder.endObject(); return new BytesRestResponse(OK, builder); } }); }
Example #16
Source File: IndexAliasesService.java From Elasticsearch with Apache License 2.0 | 5 votes |
Query parse(AliasMetaData alias) { if (alias.filter() == null) { return null; } try { byte[] filterSource = alias.filter().uncompressed(); try (XContentParser parser = XContentFactory.xContent(filterSource).createParser(filterSource)) { ParsedQuery parsedFilter = indexQueryParser.parseInnerFilter(parser); return parsedFilter == null ? null : parsedFilter.query(); } } catch (IOException ex) { throw new AliasFilterParsingException(index, alias.getAlias(), "Invalid alias filter", ex); } }
Example #17
Source File: IndexServiceImpl.java From microservices-platform with Apache License 2.0 | 5 votes |
@Override public Map<String, Object> show(String indexName) throws IOException { GetIndexRequest request = new GetIndexRequest(); request.indices(indexName); GetIndexResponse getIndexResponse = elasticsearchRestTemplate.getClient() .indices().get(request, RequestOptions.DEFAULT); ImmutableOpenMap<String, MappingMetaData> mappOpenMap = getIndexResponse.getMappings().get(indexName); List<AliasMetaData> indexAliases = getIndexResponse.getAliases().get(indexName); String settingsStr = getIndexResponse.getSettings().get(indexName).toString(); Object settingsObj = null; if (StrUtil.isNotEmpty(settingsStr)) { settingsObj = JSONObject.parse(settingsStr); } Map<String, Object> result = new HashMap<>(1); Map<String, Object> indexMap = new HashMap<>(3); Map<String, Object> mappMap = new HashMap<>(mappOpenMap.size()); List<String> aliasesList = new ArrayList<>(indexAliases.size()); indexMap.put("aliases", aliasesList); indexMap.put("settings", settingsObj); indexMap.put("mappings", mappMap); result.put(indexName, indexMap); //获取mappings数据 for (ObjectCursor<String> key : mappOpenMap.keys()) { MappingMetaData data = mappOpenMap.get(key.value); Map<String, Object> dataMap = data.getSourceAsMap(); mappMap.put(key.value, dataMap); } //获取aliases数据 for (AliasMetaData aliases : indexAliases) { aliasesList.add(aliases.getAlias()); } return result; }
Example #18
Source File: GetAliasesResponse.java From Elasticsearch with Apache License 2.0 | 4 votes |
public ImmutableOpenMap<String, List<AliasMetaData>> getAliases() { return aliases; }
Example #19
Source File: GetAliasesResponse.java From Elasticsearch with Apache License 2.0 | 4 votes |
public GetAliasesResponse(ImmutableOpenMap<String, List<AliasMetaData>> aliases) { this.aliases = aliases; }
Example #20
Source File: TransportGetIndexAction.java From Elasticsearch with Apache License 2.0 | 4 votes |
@Override protected void doMasterOperation(final GetIndexRequest request, String[] concreteIndices, final ClusterState state, final ActionListener<GetIndexResponse> listener) { ImmutableOpenMap<String, List<Entry>> warmersResult = ImmutableOpenMap.of(); ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappingsResult = ImmutableOpenMap.of(); ImmutableOpenMap<String, List<AliasMetaData>> aliasesResult = ImmutableOpenMap.of(); ImmutableOpenMap<String, Settings> settings = ImmutableOpenMap.of(); Feature[] features = request.features(); boolean doneAliases = false; boolean doneMappings = false; boolean doneSettings = false; boolean doneWarmers = false; for (Feature feature : features) { switch (feature) { case WARMERS: if (!doneWarmers) { warmersResult = state.metaData().findWarmers(concreteIndices, request.types(), Strings.EMPTY_ARRAY); doneWarmers = true; } break; case MAPPINGS: if (!doneMappings) { mappingsResult = state.metaData().findMappings(concreteIndices, request.types()); doneMappings = true; } break; case ALIASES: if (!doneAliases) { aliasesResult = state.metaData().findAliases(Strings.EMPTY_ARRAY, concreteIndices); doneAliases = true; } break; case SETTINGS: if (!doneSettings) { ImmutableOpenMap.Builder<String, Settings> settingsMapBuilder = ImmutableOpenMap.builder(); for (String index : concreteIndices) { Settings indexSettings = state.metaData().index(index).getSettings(); if (request.humanReadable()) { indexSettings = IndexMetaData.addHumanReadableSettings(indexSettings); } settingsMapBuilder.put(index, indexSettings); } settings = settingsMapBuilder.build(); doneSettings = true; } break; default: throw new IllegalStateException("feature [" + feature + "] is not valid"); } } listener.onResponse(new GetIndexResponse(concreteIndices, warmersResult, mappingsResult, aliasesResult, settings)); }
Example #21
Source File: GetIndexResponse.java From Elasticsearch with Apache License 2.0 | 4 votes |
public ImmutableOpenMap<String, List<AliasMetaData>> aliases() { return aliases; }
Example #22
Source File: GetIndexResponse.java From Elasticsearch with Apache License 2.0 | 4 votes |
public ImmutableOpenMap<String, List<AliasMetaData>> getAliases() { return aliases(); }
Example #23
Source File: IndexAliasesService.java From Elasticsearch with Apache License 2.0 | 4 votes |
void add(String alias, @Nullable CompressedXContent filter) { AliasMetaData aliasMetaData = AliasMetaData.builder(alias).filter(filter).build(); aliases = ImmutableOpenMap.builder(aliases).fPut(alias, aliasMetaData).build(); }
Example #24
Source File: IndexAliasesService.java From Elasticsearch with Apache License 2.0 | 4 votes |
public void setAliases(ImmutableOpenMap<String, AliasMetaData> aliases) { this.aliases = aliases; }
Example #25
Source File: SwapRelationsOperation.java From crate with Apache License 2.0 | 4 votes |
private void addSourceIndicesRenamedToTargetName(ClusterState state, MetaData metaData, MetaData.Builder updatedMetaData, ClusterBlocks.Builder blocksBuilder, RoutingTable.Builder routingBuilder, RelationName source, RelationName target, Consumer<String> onProcessedIndex) { String sourceTemplateName = PartitionName.templateName(source.schema(), source.name()); IndexTemplateMetaData sourceTemplate = metaData.templates().get(sourceTemplateName); for (Index sourceIndex : indexNameResolver.concreteIndices( state, IndicesOptions.LENIENT_EXPAND_OPEN, source.indexNameOrAlias())) { String sourceIndexName = sourceIndex.getName(); IndexMetaData sourceMd = metaData.getIndexSafe(sourceIndex); IndexMetaData targetMd; if (sourceTemplate == null) { targetMd = IndexMetaData.builder(sourceMd) .removeAllAliases() .index(target.indexNameOrAlias()) .build(); onProcessedIndex.accept(target.indexNameOrAlias()); } else { PartitionName partitionName = PartitionName.fromIndexOrTemplate(sourceIndexName); String targetIndexName = IndexParts.toIndexName(target, partitionName.ident()); targetMd = IndexMetaData.builder(sourceMd) .removeAllAliases() .putAlias(AliasMetaData.builder(target.indexNameOrAlias()).build()) .index(targetIndexName) .build(); onProcessedIndex.accept(targetIndexName); } updatedMetaData.put(targetMd, true); blocksBuilder.addBlocks(targetMd); routingBuilder.addAsFromCloseToOpen(targetMd); } if (sourceTemplate != null) { IndexTemplateMetaData.Builder templateBuilder = Templates.copyWithNewName(sourceTemplate, target); updatedMetaData.put(templateBuilder); } }
Example #26
Source File: RenameTableClusterStateExecutor.java From crate with Apache License 2.0 | 4 votes |
public ClusterState execute(ClusterState currentState, RenameTableRequest request) throws Exception { RelationName source = request.sourceTableIdent(); RelationName target = request.targetTableIdent(); boolean isPartitioned = request.isPartitioned(); MetaData currentMetaData = currentState.getMetaData(); MetaData.Builder newMetaData = MetaData.builder(currentMetaData); if (isPartitioned) { IndexTemplateMetaData indexTemplateMetaData = DDLClusterStateHelpers.templateMetaData(currentMetaData, source); if (indexTemplateMetaData == null) { throw new IndexTemplateMissingException("Template for partitioned table is missing"); } renameTemplate(newMetaData, indexTemplateMetaData, target); } RoutingTable.Builder newRoutingTable = RoutingTable.builder(currentState.routingTable()); ClusterBlocks.Builder blocksBuilder = ClusterBlocks.builder().blocks(currentState.blocks()); logger.info("renaming table '{}' to '{}'", source.fqn(), target.fqn()); try { Index[] sourceIndices = indexNameExpressionResolver.concreteIndices( currentState, STRICT_INDICES_OPTIONS, source.indexNameOrAlias()); for (Index sourceIndex : sourceIndices) { IndexMetaData sourceIndexMetaData = currentMetaData.getIndexSafe(sourceIndex); String sourceIndexName = sourceIndex.getName(); newMetaData.remove(sourceIndexName); newRoutingTable.remove(sourceIndexName); blocksBuilder.removeIndexBlocks(sourceIndexName); IndexMetaData targetMd; if (isPartitioned) { PartitionName partitionName = PartitionName.fromIndexOrTemplate(sourceIndexName); String targetIndexName = IndexParts.toIndexName(target, partitionName.ident()); targetMd = IndexMetaData.builder(sourceIndexMetaData) .removeAllAliases() .putAlias(AliasMetaData.builder(target.indexNameOrAlias()).build()) .index(targetIndexName) .build(); } else { targetMd = IndexMetaData.builder(sourceIndexMetaData) .index(target.indexNameOrAlias()) .build(); } newMetaData.put(targetMd, true); newRoutingTable.addAsFromCloseToOpen(targetMd); blocksBuilder.addBlocks(targetMd); } } catch (IndexNotFoundException e) { if (isPartitioned == false) { throw e; } // empty partition case, no indices, just a template exists } ClusterState clusterStateAfterRename = ClusterState.builder(currentState) .metaData(newMetaData) .routingTable(newRoutingTable.build()) .blocks(blocksBuilder) .build(); return allocationService.reroute( ddlClusterStateService.onRenameTable(clusterStateAfterRename, source, target, request.isPartitioned()), "rename-table" ); }
Example #27
Source File: DocSchemaInfo.java From crate with Apache License 2.0 | 4 votes |
private void invalidateAliases(ImmutableOpenMap<String, AliasMetaData> aliases) { assert aliases != null : "aliases must not be null"; if (aliases.size() > 0) { aliases.keysIt().forEachRemaining(docTableByName::remove); } }