Search in sources :

Example 1 with PutIndexTemplateRequest

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);
}
Also used : PutIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest)

Example 2 with PutIndexTemplateRequest

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();
}
Also used : AcknowledgedResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.master.AcknowledgedResponse) PutIndexTemplateRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest)

Example 3 with PutIndexTemplateRequest

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;
}
Also used : ExplainRequest(org.elasticsearch.action.explain.ExplainRequest) GetMappingsRequest(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest) SearchTemplateRequest(org.elasticsearch.script.mustache.SearchTemplateRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteByQueryRequest(org.elasticsearch.index.reindex.DeleteByQueryRequest) FieldCapabilitiesRequest(org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest) CountRequest(org.elasticsearch.client.core.CountRequest) IndexTemplatesExistRequest(org.elasticsearch.client.indices.IndexTemplatesExistRequest) GetStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) GetRequest(org.elasticsearch.action.get.GetRequest) RankEvalRequest(org.elasticsearch.index.rankeval.RankEvalRequest) GetAliasesRequest(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest) IndicesAliasesRequest(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest) AbstractBulkByScrollRequest(org.elasticsearch.index.reindex.AbstractBulkByScrollRequest) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) GetSettingsRequest(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) PutStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) PutIndexTemplateRequest(org.elasticsearch.client.indices.PutIndexTemplateRequest) DeleteStoredScriptRequest(org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) MultiGetRequest(org.elasticsearch.action.get.MultiGetRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) OpenIndexRequest(org.elasticsearch.action.admin.indices.open.OpenIndexRequest) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) UpdateByQueryRequest(org.elasticsearch.index.reindex.UpdateByQueryRequest) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) GetIndexTemplatesRequest(org.elasticsearch.client.indices.GetIndexTemplatesRequest) GetFieldMappingsRequest(org.elasticsearch.client.indices.GetFieldMappingsRequest) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) DocWriteRequest(org.elasticsearch.action.DocWriteRequest) Request(org.elasticsearch.client.Request) AnalyzeRequest(org.elasticsearch.client.indices.AnalyzeRequest) CloseIndexRequest(org.elasticsearch.action.admin.indices.close.CloseIndexRequest) RethrottleRequest(org.elasticsearch.client.RethrottleRequest) FlushRequest(org.elasticsearch.action.admin.indices.flush.FlushRequest) PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) SearchScrollRequest(org.elasticsearch.action.search.SearchScrollRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ReindexRequest(org.elasticsearch.index.reindex.ReindexRequest)

Example 4 with PutIndexTemplateRequest

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;
}
Also used : Alias(org.elasticsearch.action.admin.indices.alias.Alias) PutIndexTemplateRequest(org.elasticsearch.client.indices.PutIndexTemplateRequest) AliasActionParameters(org.springframework.data.elasticsearch.core.index.AliasActionParameters) MoreLikeThisQueryBuilder(org.elasticsearch.index.query.MoreLikeThisQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions)

Example 5 with PutIndexTemplateRequest

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);
}
Also used : PutTemplateRequest(org.springframework.data.elasticsearch.core.index.PutTemplateRequest) AliasAction(org.springframework.data.elasticsearch.core.index.AliasAction) PutIndexTemplateRequest(org.elasticsearch.client.indices.PutIndexTemplateRequest) AliasActions(org.springframework.data.elasticsearch.core.index.AliasActions) Test(org.junit.jupiter.api.Test)

Aggregations

PutIndexTemplateRequest (org.elasticsearch.client.indices.PutIndexTemplateRequest)14 JSONObject (com.alibaba.fastjson.JSONObject)5 IOException (java.io.IOException)5 Alias (org.elasticsearch.action.admin.indices.alias.Alias)4 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)3 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)3 AliasActions (org.springframework.data.elasticsearch.core.index.AliasActions)3 IndicesAliasesRequest (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest)2 GetAliasesRequest (org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest)2 GetSettingsRequest (org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest)2 DeleteIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)2 IndexRequest (org.elasticsearch.action.index.IndexRequest)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 PutIndexTemplateRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.PutIndexTemplateRequest)2 Collection (com.danawa.dsearch.server.entity.Collection)1 DuplicateException (com.danawa.dsearch.server.excpetions.DuplicateException)1 Map (java.util.Map)1 Set (java.util.Set)1 Log (org.apache.commons.logging.Log)1