Search in sources :

Example 21 with CreateIndexResponse

use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project vertexium by visallo.

the class Elasticsearch5SearchIndex method createIndex.

@SuppressWarnings("unused")
protected void createIndex(String indexName) throws IOException {
    CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).setSettings(XContentFactory.jsonBuilder().startObject().startObject("analysis").startObject("normalizer").startObject(LOWERCASER_NORMALIZER_NAME).field("type", "custom").array("filter", "lowercase").endObject().endObject().endObject().field("number_of_shards", getConfig().getNumberOfShards()).field("number_of_replicas", getConfig().getNumberOfReplicas()).field("index.mapping.total_fields.limit", getConfig().getIndexMappingTotalFieldsLimit()).field("refresh_interval", getConfig().getIndexRefreshInterval()).endObject()).execute().actionGet();
    ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().execute().actionGet();
    LOGGER.debug("Index status: %s", health.toString());
    if (health.isTimedOut()) {
        LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName);
    }
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Example 22 with CreateIndexResponse

use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project vertexium by visallo.

the class Elasticsearch7SearchIndex method createIndex.

@SuppressWarnings("unused")
protected void createIndex(String indexName) throws IOException {
    CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).setSettings(XContentFactory.jsonBuilder().startObject().startObject("analysis").startObject("normalizer").startObject(LOWERCASER_NORMALIZER_NAME).field("type", "custom").array("filter", "lowercase").endObject().endObject().endObject().field("number_of_shards", getConfig().getNumberOfShards()).field("number_of_replicas", getConfig().getNumberOfReplicas()).field("index.mapping.total_fields.limit", getConfig().getIndexMappingTotalFieldsLimit()).field("refresh_interval", getConfig().getIndexRefreshInterval()).endObject()).execute().actionGet();
    ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName).setWaitForGreenStatus().execute().actionGet();
    LOGGER.debug("Index status: %s", health.toString());
    if (health.isTimedOut()) {
        LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName);
    }
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Example 23 with CreateIndexResponse

use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project ccd-definition-store-api by hmcts.

the class HighLevelCCDElasticClient method createIndex.

@Override
public boolean createIndex(String indexName, String alias) throws IOException {
    log.info("creating index {} with alias {}", indexName, alias);
    CreateIndexRequest request = new CreateIndexRequest(indexName);
    request.alias(new Alias(alias));
    String file = (alias.equalsIgnoreCase(GLOBAL_SEARCH)) ? GLOBAL_SEARCH_CASES_INDEX_SETTINGS_JSON : CASES_INDEX_SETTINGS_JSON;
    request.settings(casesIndexSettings(file));
    CreateIndexResponse createIndexResponse = elasticClient.indices().create(request, RequestOptions.DEFAULT);
    log.info("index created: {}", createIndexResponse.isAcknowledged());
    return createIndexResponse.isAcknowledged();
}
Also used : Alias(org.elasticsearch.action.admin.indices.alias.Alias) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Example 24 with CreateIndexResponse

use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project c2mon by c2mon.

the class ElasticsearchClientTransport method createIndex.

@Override
public boolean createIndex(IndexMetadata indexMetadata, String mapping) {
    CreateIndexRequestBuilder builder = client.admin().indices().prepareCreate(indexMetadata.getName());
    builder.setSettings(Settings.builder().put("number_of_shards", properties.getShardsPerIndex()).put("number_of_replicas", properties.getReplicasPerShard()).build());
    if (mapping != null) {
        builder.addMapping(mapping, XContentType.JSON);
    }
    log.debug("Creating new index with name {}", indexMetadata.getName());
    try {
        CreateIndexResponse response = builder.get();
        return response.isAcknowledged();
    } catch (ResourceAlreadyExistsException e) {
        log.debug("Index already exists.", e);
    }
    return false;
}
Also used : CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) ResourceAlreadyExistsException(org.elasticsearch.ResourceAlreadyExistsException) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse)

Example 25 with CreateIndexResponse

use of org.elasticsearch.action.admin.indices.create.CreateIndexResponse in project cdap by cdapio.

the class ElasticsearchMetadataStorage method createIndex.

@Override
public void createIndex() throws IOException {
    if (created) {
        return;
    }
    synchronized (this) {
        if (created) {
            return;
        }
        GetIndexRequest request = new GetIndexRequest();
        request.indices(indexName);
        RestHighLevelClient client = getClient();
        if (!client.indices().exists(request, RequestOptions.DEFAULT)) {
            String settings = createSettings();
            LOG.info("Creating index '{}' with settings: {}", indexName, settings);
            CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
            createIndexRequest.settings(settings, XContentType.JSON);
            createIndexRequest.mapping(DOC_TYPE, createMappings(), XContentType.JSON);
            CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
            if (!response.isAcknowledged()) {
                throw new IOException("Create index request was not acknowledged by EleasticSearch: " + response);
            }
        }
        request = new GetIndexRequest();
        request.indices(indexName);
        GetIndexResponse response = client.indices().get(request, RequestOptions.DEFAULT);
        Settings settings = response.getSettings().get(indexName);
        if (settings == null) {
            throw new IOException("Unable to obtain Elasticsearch settings for index " + indexName);
        }
        String maxWindow = response.getSetting(indexName, "index.max_result_window");
        if (maxWindow != null) {
            maxWindowSize = Integer.parseInt(maxWindow);
        }
        LOG.debug("Using Elasticsearch index {} with 'max_result_window' of {}", indexName, maxWindowSize);
        // For some unknown reason, multi-get fails immediately after creating an index
        // However, performing one regular read appears to fix that, perhaps it waits until the index is ready?
        // Hence, perform one read to ensure the index is ready to use.
        readFromIndex(MetadataEntity.ofNamespace("system"));
        created = true;
    }
}
Also used : GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)49 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)24 IOException (java.io.IOException)16 Settings (org.elasticsearch.common.settings.Settings)12 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)8 ElasticsearchException (org.elasticsearch.ElasticsearchException)7 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)5 GetIndexRequest (org.elasticsearch.action.admin.indices.get.GetIndexRequest)5 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)5 Alias (org.elasticsearch.action.admin.indices.alias.Alias)4 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 ResourceAlreadyExistsException (org.elasticsearch.ResourceAlreadyExistsException)3 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)3 GetIndexResponse (org.elasticsearch.action.admin.indices.get.GetIndexResponse)3 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 RelationName (io.crate.metadata.RelationName)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2