use of org.springframework.data.elasticsearch.core.index.AliasData in project spring-data-elasticsearch by spring-projects.
the class ResponseConverter method getTemplateData.
// endregion
// region templates
@Nullable
public static TemplateData getTemplateData(GetIndexTemplatesResponse getIndexTemplatesResponse, String templateName) {
for (IndexTemplateMetadata indexTemplateMetadata : getIndexTemplatesResponse.getIndexTemplates()) {
if (indexTemplateMetadata.name().equals(templateName)) {
Settings settings = new Settings();
org.elasticsearch.common.settings.Settings templateSettings = indexTemplateMetadata.settings();
templateSettings.keySet().forEach(key -> settings.put(key, templateSettings.get(key)));
Map<String, AliasData> aliases = new LinkedHashMap<>();
ImmutableOpenMap<String, AliasMetadata> aliasesResponse = indexTemplateMetadata.aliases();
Iterator<String> keysIt = aliasesResponse.keysIt();
while (keysIt.hasNext()) {
String key = keysIt.next();
aliases.put(key, ResponseConverter.toAliasData(aliasesResponse.get(key)));
}
return //
TemplateData.builder().withIndexPatterns(indexTemplateMetadata.patterns().toArray(new String[0])).withSettings(//
settings).withMapping(//
Document.from(indexTemplateMetadata.mappings().getSourceAsMap())).withAliases(//
aliases).withOrder(//
indexTemplateMetadata.order()).withVersion(indexTemplateMetadata.version()).build();
}
}
return null;
}
use of org.springframework.data.elasticsearch.core.index.AliasData in project spring-data-elasticsearch by spring-projects.
the class ResponseConverter method getIndexInformations.
/**
* get the index informations from a {@link org.elasticsearch.action.admin.indices.get.GetIndexResponse} (transport
* client)
*
* @param getIndexResponse the index response, must not be {@literal null}
* @return list of {@link IndexInformation}s for the different indices
*/
public static List<IndexInformation> getIndexInformations(org.elasticsearch.action.admin.indices.get.GetIndexResponse getIndexResponse) {
List<IndexInformation> indexInformationList = new ArrayList<>();
for (String indexName : getIndexResponse.getIndices()) {
Settings settings = settingsFromGetIndexResponse(getIndexResponse, indexName);
Document mappings = mappingsFromGetIndexResponse(getIndexResponse, indexName);
List<AliasData> aliases = aliasDataFromIndexResponse(getIndexResponse, indexName);
indexInformationList.add(IndexInformation.of(indexName, settings, mappings, aliases));
}
return indexInformationList;
}
use of org.springframework.data.elasticsearch.core.index.AliasData in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexOperationsTest method shouldGetTemplate.
// DATAES-612
@Test
void shouldGetTemplate() throws JSONException {
ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
org.springframework.data.elasticsearch.core.document.Document mapping = indexOps.createMapping(TemplateClass.class).block();
Settings settings = indexOps.createSettings(TemplateClass.class).block();
AliasActions aliasActions = new AliasActions(new AliasAction.Add(AliasActionParameters.builderForTemplate().withAliases("alias1", "alias2").build()));
PutTemplateRequest putTemplateRequest = //
PutTemplateRequest.builder("test-template", "log-*").withSettings(//
settings).withMappings(//
mapping).withAliasActions(//
aliasActions).withOrder(//
11).withVersion(//
42).build();
Boolean acknowledged = indexOps.putTemplate(putTemplateRequest).block();
assertThat(acknowledged).isTrue();
GetTemplateRequest getTemplateRequest = new GetTemplateRequest(putTemplateRequest.getName());
TemplateData templateData = indexOps.getTemplate(getTemplateRequest).block();
assertThat(templateData).isNotNull();
assertThat(templateData.getIndexPatterns()).containsExactlyInAnyOrder(putTemplateRequest.getIndexPatterns());
assertEquals(settings.toJson(), templateData.getSettings().toJson(), false);
assertEquals(mapping.toJson(), templateData.getMapping().toJson(), false);
Map<String, AliasData> aliases = templateData.getAliases();
assertThat(aliases).hasSize(2);
AliasData alias1 = aliases.get("alias1");
assertThat(alias1.getAlias()).isEqualTo("alias1");
AliasData alias2 = aliases.get("alias2");
assertThat(alias2.getAlias()).isEqualTo("alias2");
assertThat(templateData.getOrder()).isEqualTo(putTemplateRequest.getOrder());
assertThat(templateData.getVersion()).isEqualTo(putTemplateRequest.getVersion());
}
use of org.springframework.data.elasticsearch.core.index.AliasData in project spring-data-elasticsearch by spring-projects.
the class ReactiveElasticsearchTemplateIntegrationTests method shouldReturnInformationListOfAllIndices.
// #1646, #1718
@Test
@DisplayName("should return a list of info for specific index")
void shouldReturnInformationListOfAllIndices() {
String indexName = indexNameProvider.indexName();
String aliasName = indexName + "-alias";
ReactiveIndexOperations indexOps = operations.indexOps(EntityWithSettingsAndMappingsReactive.class);
// beforeEach uses SampleEntity, so recreate the index here
indexOps.delete().then(indexOps.createWithMapping()).block();
AliasActionParameters parameters = AliasActionParameters.builder().withAliases(aliasName).withIndices(indexName).withIsHidden(false).withIsWriteIndex(false).withRouting("indexrouting").withSearchRouting("searchrouting").build();
indexOps.alias(new AliasActions(new AliasAction.Add(parameters))).block();
indexOps.getInformation().as(StepVerifier::create).consumeNextWith(indexInformation -> {
assertThat(indexInformation.getName()).isEqualTo(indexName);
assertThat(indexInformation.getSettings().get("index.number_of_shards")).isEqualTo("1");
assertThat(indexInformation.getSettings().get("index.number_of_replicas")).isEqualTo("0");
assertThat(indexInformation.getSettings().get("index.analysis.analyzer.emailAnalyzer.type")).isEqualTo("custom");
assertThat(indexInformation.getAliases()).hasSize(1);
AliasData aliasData = indexInformation.getAliases().get(0);
assertThat(aliasData.getAlias()).isEqualTo(aliasName);
assertThat(aliasData.isHidden()).isEqualTo(false);
assertThat(aliasData.isWriteIndex()).isEqualTo(false);
assertThat(aliasData.getIndexRouting()).isEqualTo("indexrouting");
assertThat(aliasData.getSearchRouting()).isEqualTo("searchrouting");
String expectedMappings = "{\"properties\":{\"email\":{\"type\":\"text\",\"analyzer\":\"emailAnalyzer\"}}}";
try {
JSONAssert.assertEquals(expectedMappings, indexInformation.getMapping().toJson(), false);
} catch (JSONException e) {
e.printStackTrace();
}
}).verifyComplete();
}
use of org.springframework.data.elasticsearch.core.index.AliasData in project spring-data-elasticsearch by spring-projects.
the class ResponseConverter method getIndexInformations.
// endregion
// region index informations
/**
* get the index informations from a {@link GetIndexResponse}
*
* @param getIndexResponse the index response, must not be {@literal null}
* @return list of {@link IndexInformation}s for the different indices
*/
public static List<IndexInformation> getIndexInformations(GetIndexResponse getIndexResponse) {
Assert.notNull(getIndexResponse, "getIndexResponse must not be null");
List<IndexInformation> indexInformationList = new ArrayList<>();
for (String indexName : getIndexResponse.getIndices()) {
Settings settings = settingsFromGetIndexResponse(getIndexResponse, indexName);
Document mappings = mappingsFromGetIndexResponse(getIndexResponse, indexName);
List<AliasData> aliases = aliasDataFromIndexResponse(getIndexResponse, indexName);
indexInformationList.add(IndexInformation.of(indexName, settings, mappings, aliases));
}
return indexInformationList;
}
Aggregations