use of org.elasticsearch.cluster.metadata.AliasMetaData 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.AliasMetaData in project crate by crate.
the class TransportCreatePartitionsAction method applyTemplates.
private void applyTemplates(Map<String, Map<String, Object>> mappings, Map<String, AliasMetadata> templatesAliases, List<String> templateNames, List<IndexTemplateMetadata> templates) throws Exception {
for (IndexTemplateMetadata template : templates) {
templateNames.add(template.getName());
for (ObjectObjectCursor<String, CompressedXContent> cursor : template.mappings()) {
if (mappings.containsKey(cursor.key)) {
XContentHelper.mergeDefaults(mappings.get(cursor.key), parseMapping(cursor.value.string()));
} else {
mappings.put(cursor.key, parseMapping(cursor.value.string()));
}
}
// handle aliases
for (ObjectObjectCursor<String, AliasMetadata> cursor : template.aliases()) {
AliasMetadata aliasMetadata = cursor.value;
templatesAliases.put(aliasMetadata.alias(), aliasMetadata);
}
}
}
use of org.elasticsearch.cluster.metadata.AliasMetaData in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method aliases.
@Override
public Map<String, Set<String>> aliases(String indexPattern) {
final GetAliasesRequest request = new GetAliasesRequest().indices(indexPattern).indicesOptions(IndicesOptions.fromOptions(false, false, true, false));
final GetAliasesResponse result = client.execute((c, requestOptions) -> c.indices().getAlias(request, requestOptions), "Couldn't collect aliases for index pattern " + indexPattern);
return result.getAliases().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(AliasMetadata::alias).collect(Collectors.toSet())));
}
use of org.elasticsearch.cluster.metadata.AliasMetaData in project crate by crate.
the class DocIndexMetaDataTest method testMergePartitionWithDifferentShardsAndReplicas.
@Test
public void testMergePartitionWithDifferentShardsAndReplicas() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").field("primary_keys", "id").startArray("partitioned_by").startArray().value("datum").value("date").endArray().endArray().endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().endObject();
Settings templateSettings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 2).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 6).build();
IndexMetaData metaData = getIndexMetaData("test1", builder, templateSettings, null);
DocIndexMetaData md = newMeta(metaData, "test1");
PartitionName partitionName = new PartitionName("test1", Arrays.asList(new BytesRef("0")));
Settings partitionSettings = Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 10).put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 50).build();
AliasMetaData aliasMetaData = AliasMetaData.newAliasMetaDataBuilder("test1").build();
IndexMetaData partitionMetaData = getIndexMetaData(partitionName.asIndexName(), builder, partitionSettings, aliasMetaData);
DocIndexMetaData partitionMD = newMeta(partitionMetaData, partitionName.asIndexName());
assertThat(partitionMD.aliases().size(), is(1));
assertThat(partitionMD.aliases(), hasItems("test1"));
assertThat(partitionMD.isAlias(), is(false));
assertThat(partitionMD.concreteIndexName(), is(partitionName.asIndexName()));
DocIndexMetaData merged = md.merge(partitionMD, mock(TransportPutIndexTemplateAction.class), true);
assertThat(merged.numberOfReplicas(), is(BytesRefs.toBytesRef(2)));
assertThat(merged.numberOfShards(), is(6));
}
use of org.elasticsearch.cluster.metadata.AliasMetaData in project elasticsearch by elastic.
the class RestGetIndicesAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
String[] featureParams = request.paramAsStringArray("type", null);
// Work out if the indices is a list of features
if (featureParams == null && indices.length > 0 && indices[0] != null && indices[0].startsWith("_") && !"_all".equals(indices[0])) {
featureParams = indices;
indices = new String[] { "_all" };
}
final GetIndexRequest getIndexRequest = new GetIndexRequest();
getIndexRequest.indices(indices);
if (featureParams != null) {
Feature[] features = Feature.convertToFeatures(featureParams);
getIndexRequest.features(features);
}
getIndexRequest.indicesOptions(IndicesOptions.fromRequest(request, getIndexRequest.indicesOptions()));
getIndexRequest.local(request.paramAsBoolean("local", getIndexRequest.local()));
getIndexRequest.humanReadable(request.paramAsBoolean("human", false));
final boolean defaults = request.paramAsBoolean("include_defaults", false);
return channel -> client.admin().indices().getIndex(getIndexRequest, new RestBuilderListener<GetIndexResponse>(channel) {
@Override
public RestResponse buildResponse(final GetIndexResponse response, final XContentBuilder builder) throws Exception {
builder.startObject();
{
for (final String index : response.indices()) {
builder.startObject(index);
{
for (final Feature feature : getIndexRequest.features()) {
switch(feature) {
case ALIASES:
writeAliases(response.aliases().get(index), builder, request);
break;
case MAPPINGS:
writeMappings(response.mappings().get(index), builder);
break;
case SETTINGS:
writeSettings(response.settings().get(index), builder, request, defaults);
break;
default:
throw new IllegalStateException("feature [" + feature + "] is not valid");
}
}
}
builder.endObject();
}
}
builder.endObject();
return new BytesRestResponse(OK, builder);
}
private void writeAliases(final List<AliasMetaData> aliases, final XContentBuilder builder, final Params params) throws IOException {
builder.startObject("aliases");
{
if (aliases != null) {
for (final AliasMetaData alias : aliases) {
AliasMetaData.Builder.toXContent(alias, builder, params);
}
}
}
builder.endObject();
}
private void writeMappings(final ImmutableOpenMap<String, MappingMetaData> mappings, final XContentBuilder builder) throws IOException {
builder.startObject("mappings");
{
if (mappings != null) {
for (final ObjectObjectCursor<String, MappingMetaData> typeEntry : mappings) {
builder.field(typeEntry.key);
builder.map(typeEntry.value.sourceAsMap());
}
}
}
builder.endObject();
}
private void writeSettings(final Settings settings, final XContentBuilder builder, final Params params, final boolean defaults) throws IOException {
builder.startObject("settings");
{
settings.toXContent(builder, params);
}
builder.endObject();
if (defaults) {
builder.startObject("defaults");
{
settingsFilter.filter(indexScopedSettings.diff(settings, RestGetIndicesAction.this.settings)).toXContent(builder, request);
}
builder.endObject();
}
}
});
}
Aggregations