use of org.springframework.data.elasticsearch.core.index.TemplateData in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexTemplate method getTemplate.
@Override
public Mono<TemplateData> getTemplate(GetTemplateRequest getTemplateRequest) {
Assert.notNull(getTemplateRequest, "getTemplateRequest must not be null");
GetIndexTemplatesRequest getIndexTemplatesRequest = requestFactory.getIndexTemplatesRequest(getTemplateRequest);
return Mono.from(operations.executeWithIndicesClient(client -> client.getTemplate(getIndexTemplatesRequest))).flatMap(response -> {
if (response != null) {
TemplateData templateData = ResponseConverter.getTemplateData(response, getTemplateRequest.getTemplateName());
if (templateData != null) {
return Mono.just(templateData);
}
}
return Mono.empty();
});
}
use of org.springframework.data.elasticsearch.core.index.TemplateData 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());
}
Aggregations