use of org.elasticsearch.action.admin.indices.get.GetIndexResponse in project graylog2-server by Graylog2.
the class Indices method getIndexNamesAndAliases.
@NotNull
public Map<String, Set<String>> getIndexNamesAndAliases(String indexPattern) {
// only request indices matching the name or pattern in `indexPattern` and only get the alias names for each index,
// not the settings or mappings
final GetIndexRequestBuilder getIndexRequestBuilder = c.admin().indices().prepareGetIndex();
getIndexRequestBuilder.addFeatures(GetIndexRequest.Feature.ALIASES);
getIndexRequestBuilder.setIndices(indexPattern);
final GetIndexResponse getIndexResponse = c.admin().indices().getIndex(getIndexRequestBuilder.request()).actionGet();
final String[] indices = getIndexResponse.indices();
final ImmutableOpenMap<String, List<AliasMetaData>> aliases = getIndexResponse.aliases();
final Map<String, Set<String>> indexAliases = Maps.newHashMap();
for (String index : indices) {
final List<AliasMetaData> aliasMetaData = aliases.get(index);
if (aliasMetaData == null) {
indexAliases.put(index, Collections.emptySet());
} else {
indexAliases.put(index, aliasMetaData.stream().map(AliasMetaData::alias).collect(toSet()));
}
}
return indexAliases;
}
use of org.elasticsearch.action.admin.indices.get.GetIndexResponse in project metron by apache.
the class ElasticsearchColumnMetadataDaoTest method setup.
/**
* @param indices The names of all indices that will exist.
* @param mappings The index mappings.
* @return An object to test.
*/
public ElasticsearchColumnMetadataDao setup(String[] indices, ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings) {
AdminClient adminClient = mock(AdminClient.class);
IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class);
GetIndexRequestBuilder getIndexRequestBuilder = mock(GetIndexRequestBuilder.class);
GetIndexResponse getIndexResponse = mock(GetIndexResponse.class);
ActionFuture getMappingsActionFuture = mock(ActionFuture.class);
GetMappingsResponse getMappingsResponse = mock(GetMappingsResponse.class);
// setup the mocks so that a set of indices are available to the DAO
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(indicesAdminClient.prepareGetIndex()).thenReturn(getIndexRequestBuilder);
when(getIndexRequestBuilder.setFeatures()).thenReturn(getIndexRequestBuilder);
when(getIndexRequestBuilder.get()).thenReturn(getIndexResponse);
when(getIndexResponse.getIndices()).thenReturn(indices);
// setup the mocks so that a set of mappings are available to the DAO
when(indicesAdminClient.getMappings(any())).thenReturn(getMappingsActionFuture);
when(getMappingsActionFuture.actionGet()).thenReturn(getMappingsResponse);
when(getMappingsResponse.getMappings()).thenReturn(mappings);
return new ElasticsearchColumnMetadataDao(adminClient);
}
use of org.elasticsearch.action.admin.indices.get.GetIndexResponse 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();
}
}
});
}
use of org.elasticsearch.action.admin.indices.get.GetIndexResponse in project elasticsearch by elastic.
the class StaticIndexBackwardCompatibilityIT method assertIndexSanity.
private void assertIndexSanity(String index) {
GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().get();
assertEquals(1, getIndexResponse.indices().length);
assertEquals(index, getIndexResponse.indices()[0]);
ensureYellow(index);
SearchResponse test = client().prepareSearch(index).get();
assertThat(test.getHits().getTotalHits(), greaterThanOrEqualTo(1L));
}
use of org.elasticsearch.action.admin.indices.get.GetIndexResponse in project fess by codelibs.
the class FessEsClient method updateAlias.
public boolean updateAlias(final String newIndex) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
String updateAlias = fessConfig.getIndexDocumentUpdateIndex();
String searchAlias = fessConfig.getIndexDocumentSearchIndex();
final GetIndexResponse response1 = client.admin().indices().prepareGetIndex().addIndices(updateAlias).execute().actionGet(fessConfig.getIndexIndicesTimeout());
final String[] updateIndices = response1.indices();
final GetIndexResponse response2 = client.admin().indices().prepareGetIndex().addIndices(searchAlias).execute().actionGet(fessConfig.getIndexIndicesTimeout());
final String[] searchIndices = response2.indices();
IndicesAliasesRequestBuilder builder = client.admin().indices().prepareAliases().addAlias(newIndex, updateAlias).addAlias(newIndex, searchAlias);
for (String index : updateIndices) {
builder.removeAlias(index, updateAlias);
}
for (String index : searchIndices) {
builder.removeAlias(index, searchAlias);
}
IndicesAliasesResponse response = builder.execute().actionGet(fessConfig.getIndexIndicesTimeout());
return response.isAcknowledged();
}
Aggregations