use of org.springframework.data.elasticsearch.core.index.PutTemplateRequest in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexOperationsTest method shouldCheckExists.
// DATAES-612
@Test
void shouldCheckExists() {
ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
String templateName = "template" + UUID.randomUUID().toString();
ExistsTemplateRequest existsTemplateRequest = new ExistsTemplateRequest(templateName);
boolean exists = indexOps.existsTemplate(existsTemplateRequest).block();
assertThat(exists).isFalse();
PutTemplateRequest putTemplateRequest = //
PutTemplateRequest.builder(templateName, "log-*").withOrder(//
11).withVersion(//
42).build();
boolean acknowledged = indexOps.putTemplate(putTemplateRequest).block();
assertThat(acknowledged).isTrue();
exists = indexOps.existsTemplate(existsTemplateRequest).block();
assertThat(exists).isTrue();
}
use of org.springframework.data.elasticsearch.core.index.PutTemplateRequest 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.PutTemplateRequest in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexOperationsTest method shouldDeleteTemplate.
// DATAES-612
@Test
void shouldDeleteTemplate() {
ReactiveIndexOperations indexOps = operations.indexOps(Entity.class);
String templateName = "template" + UUID.randomUUID().toString();
ExistsTemplateRequest existsTemplateRequest = new ExistsTemplateRequest(templateName);
PutTemplateRequest putTemplateRequest = //
PutTemplateRequest.builder(templateName, "log-*").withOrder(//
11).withVersion(//
42).build();
boolean acknowledged = indexOps.putTemplate(putTemplateRequest).block();
assertThat(acknowledged).isTrue();
boolean exists = indexOps.existsTemplate(existsTemplateRequest).block();
assertThat(exists).isTrue();
acknowledged = indexOps.deleteTemplate(new DeleteTemplateRequest(templateName)).block();
assertThat(acknowledged).isTrue();
exists = indexOps.existsTemplate(existsTemplateRequest).block();
assertThat(exists).isFalse();
}
use of org.springframework.data.elasticsearch.core.index.PutTemplateRequest in project spring-data-elasticsearch by spring-projects.
the class RequestFactoryTests method shouldCreatePutIndexTemplateRequest.
@Test
// DATAES-612
void shouldCreatePutIndexTemplateRequest() throws JSONException, IOException {
String expected = //
"{\n" + //
" \"index_patterns\": [\n" + //
" \"test-*\"\n" + //
" ],\n" + //
" \"order\": 42,\n" + //
" \"version\": 7,\n" + //
" \"settings\": {\n" + //
" \"index\": {\n" + //
" \"number_of_replicas\": \"2\",\n" + //
" \"number_of_shards\": \"3\",\n" + //
" \"refresh_interval\": \"7s\",\n" + //
" \"store\": {\n" + //
" \"type\": \"oops\"\n" + //
" }\n" + //
" }\n" + //
" },\n" + //
" \"mappings\": {\n" + //
" \"properties\": {\n" + //
" \"price\": {\n" + //
" \"type\": \"double\"\n" + //
" }\n" + //
" }\n" + //
" },\n" + //
" \"aliases\":{\n" + //
" \"alias1\": {},\n" + //
" \"alias2\": {},\n" + //
" \"alias3\": {\n" + //
" \"routing\": \"11\"\n" + //
" }\n" + //
" }\n" + //
"}\n";
org.springframework.data.elasticsearch.core.document.Document settings = org.springframework.data.elasticsearch.core.document.Document.create();
settings.put("index.number_of_replicas", 2);
settings.put("index.number_of_shards", 3);
settings.put("index.refresh_interval", "7s");
settings.put("index.store.type", "oops");
org.springframework.data.elasticsearch.core.document.Document mappings = org.springframework.data.elasticsearch.core.document.Document.parse("{\"properties\":{\"price\":{\"type\":\"double\"}}}");
AliasActions aliasActions = new AliasActions(new AliasAction.Add(AliasActionParameters.builderForTemplate().withAliases("alias1", "alias2").build()), new AliasAction.Add(AliasActionParameters.builderForTemplate().withAliases("alias3").withRouting("11").build()));
PutTemplateRequest putTemplateRequest = //
PutTemplateRequest.builder("test-template", "test-*").withSettings(//
settings).withMappings(//
mappings).withAliasActions(//
aliasActions).withOrder(//
42).withVersion(//
7).build();
PutIndexTemplateRequest putIndexTemplateRequest = requestFactory.putIndexTemplateRequest(putTemplateRequest);
String json = requestToString(putIndexTemplateRequest);
assertEquals(expected, json, false);
}
use of org.springframework.data.elasticsearch.core.index.PutTemplateRequest in project spring-data-elasticsearch by spring-projects.
the class ReactiveIndexTemplate method putTemplate.
// endregion
// region templates
@Override
public Mono<Boolean> putTemplate(PutTemplateRequest putTemplateRequest) {
Assert.notNull(putTemplateRequest, "putTemplateRequest must not be null");
PutIndexTemplateRequest putIndexTemplateRequest = requestFactory.putIndexTemplateRequest(putTemplateRequest);
return Mono.from(operations.executeWithIndicesClient(client -> client.putTemplate(putIndexTemplateRequest)));
}
Aggregations