use of org.elasticsearch.client.indices.PutIndexTemplateRequest in project graylog2-server by Graylog2.
the class ClientES7 method putTemplate.
@Override
public void putTemplate(String templateName, Map<String, Object> source) {
final PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).source(source);
client.execute((c, requestOptions) -> c.indices().putTemplate(request, requestOptions), "Unable to put template " + templateName);
}
use of org.elasticsearch.client.indices.PutIndexTemplateRequest in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method ensureIndexTemplate.
@Override
public boolean ensureIndexTemplate(String templateName, Map<String, Object> template) {
final PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).source(template);
final AcknowledgedResponse result = client.execute((c, requestOptions) -> c.indices().putTemplate(request, requestOptions), "Unable to create index template " + templateName);
return result.isAcknowledged();
}
use of org.elasticsearch.client.indices.PutIndexTemplateRequest in project spring-data-elasticsearch by spring-projects.
the class RequestConverters method putTemplate.
public static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) {
String endpoint = //
(new RequestConverters.EndpointBuilder()).addPathPartAsIs(//
"_template").addPathPart(//
putIndexTemplateRequest.name()).build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params(request);
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
if (putIndexTemplateRequest.create()) {
params.putParam("create", Boolean.TRUE.toString());
}
if (Strings.hasText(putIndexTemplateRequest.cause())) {
params.putParam("cause", putIndexTemplateRequest.cause());
}
request.setEntity(RequestConverters.createEntity(putIndexTemplateRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
}
use of org.elasticsearch.client.indices.PutIndexTemplateRequest in project spring-data-elasticsearch by spring-projects.
the class RequestFactory method putIndexTemplateRequest.
public PutIndexTemplateRequest putIndexTemplateRequest(PutTemplateRequest putTemplateRequest) {
PutIndexTemplateRequest request = new PutIndexTemplateRequest(putTemplateRequest.getName()).patterns(Arrays.asList(putTemplateRequest.getIndexPatterns()));
if (putTemplateRequest.getSettings() != null) {
request.settings(putTemplateRequest.getSettings());
}
if (putTemplateRequest.getMappings() != null) {
request.mapping(putTemplateRequest.getMappings());
}
request.order(putTemplateRequest.getOrder()).version(putTemplateRequest.getVersion());
AliasActions aliasActions = putTemplateRequest.getAliasActions();
if (aliasActions != null) {
aliasActions.getActions().forEach(aliasAction -> {
AliasActionParameters parameters = aliasAction.getParameters();
String[] parametersAliases = parameters.getAliases();
if (parametersAliases != null) {
for (String aliasName : parametersAliases) {
Alias alias = new Alias(aliasName);
if (parameters.getRouting() != null) {
alias.routing(parameters.getRouting());
}
if (parameters.getIndexRouting() != null) {
alias.indexRouting(parameters.getIndexRouting());
}
if (parameters.getSearchRouting() != null) {
alias.searchRouting(parameters.getSearchRouting());
}
if (parameters.getHidden() != null) {
alias.isHidden(parameters.getHidden());
}
if (parameters.getWriteIndex() != null) {
alias.writeIndex(parameters.getWriteIndex());
}
Query filterQuery = parameters.getFilterQuery();
if (filterQuery != null) {
elasticsearchConverter.updateQuery(filterQuery, parameters.getFilterQueryClass());
QueryBuilder queryBuilder = getFilter(filterQuery);
if (queryBuilder == null) {
queryBuilder = getQuery(filterQuery);
}
alias.filter(queryBuilder);
}
request.alias(alias);
}
}
});
}
return request;
}
use of org.elasticsearch.client.indices.PutIndexTemplateRequest 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);
}
Aggregations